Google.PowerShell.Common.AuthenticateWithSdkCredentialsExecutor.GetAccessTokenForRequestAsync C# (CSharp) 메소드

GetAccessTokenForRequestAsync() 공개 메소드

public GetAccessTokenForRequestAsync ( string authUri = null, CancellationToken cancellationToken = default(CancellationToken) ) : Task
authUri string
cancellationToken System.Threading.CancellationToken
리턴 Task
        public virtual async Task<string> GetAccessTokenForRequestAsync(string authUri = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            TokenResponse token = await ActiveUserConfig.GetActiveUserToken(cancellationToken);
            return token.AccessToken;
        }

Usage Example

        public void TestGetAccessTokenForRequestAsync()
        {
            AuthenticateWithSdkCredentialsExecutor activeUserCred = new AuthenticateWithSdkCredentialsExecutor();
            string accessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;

            TokenResponse activeToken = ActiveUserConfig.GetActiveUserToken(_cancelToken).Result;
            // The access token returned by GetAccessTokenForRequestAsync should be the same as that of active user config.
            Assert.IsTrue(
                Equals(activeToken.AccessToken, accessToken),
                "GetAccessTokenForRefreshAsync returns the wrong access token.");

            // The next call to GetAccessTokenForRequestAsync should returns the same token.
            accessToken = activeUserCred.GetAccessTokenForRequestAsync().Result;
            Assert.IsTrue(
                Equals(activeToken.AccessToken, accessToken),
                "GetAccessTokenForRefreshAsync returns the wrong access token.");
        }
All Usage Examples Of Google.PowerShell.Common.AuthenticateWithSdkCredentialsExecutor::GetAccessTokenForRequestAsync