コード例 #1
0
        public async Task AuthorizationCode_Authorize_SaveRefreshToken_AuthorizeAgain(string authorizationCode, string redirectUri)
        {
            // Create instance of authentication using one-time code, which you retrieved before this step
            var initialAuthentication = new AuthorizationCodeAuthentication(ClientId, ClientSecret, authorizationCode, redirectUri);

            // Initialize context and api
            InitializeContextAndApi(initialAuthentication);

            // Use api as usual
            var agenda = await _api.AccountClient.Agendas.Current().GetAsync();

            var contact = await _api.ContactClient.Detail(123).GetAsync();

            // Before shutting down the application, save refresh token
            var refreshToken = initialAuthentication.RefreshToken;

            // Afterwards, when loading the application, use refresh token when creating authentication
            var subsequentAuthentication = new AuthorizationCodeAuthentication(ClientId, ClientSecret, refreshToken);

            // Initialize context and api
            InitializeContextAndApi(subsequentAuthentication);

            // Use api as usual
            var issuedInvoice = await _api.IssuedInvoiceClient.DefaultAsync();
        }
コード例 #2
0
        public async Task AuthorizationCode_RetrieveAndSaveRefreshToken(string authorizationCode, string redirectUri)
        {
            // Create instance of authentication using one-time code, which you retreived before this step
            var initialAuthentication = new AuthorizationCodeAuthentication(ClientId, ClientSecret, authorizationCode, redirectUri);

            // Request access token, with this call refresh token will be requested as well
            var tokenizer = await initialAuthentication.GetTokenAsync();

            // Retrieve refresh token (both values are the same) and save it
            var refreshToken1 = tokenizer.RefreshToken;
            var refreshToken2 = initialAuthentication.RefreshToken;

            // Afterwards, refresh token is used for authentication
            var subsequentAuthentication = new AuthorizationCodeAuthentication(ClientId, ClientSecret, refreshToken1 ?? refreshToken2);

            // Initialize context and api
            InitializeContextAndApi(subsequentAuthentication);

            // Use api as usual
            var issuedInvoice = await _api.IssuedInvoiceClient.DefaultAsync();
        }