public async Task AuthenticateAsync() { var oauthHelper = new OAuth2Helper(OAuthSettings); var startUri = new Uri(oauthHelper.GetAuthorizeUrl()); var endUri = new Uri(OAuthSettings.CallbackUrl); var webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startUri, endUri); if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) { var result = webAuthenticationResult.ResponseData.ToString(); var code = oauthHelper.GetCodeFromCallback(result); AuthorizationCode = code; } else if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.ErrorHttp) { throw new Exception("HTTP Error returned by AuthenticateAsync."); //OutputToken("HTTP Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseErrorDetail.ToString()); } else { throw new Exception("Error returned by AuthenticateAsync."); //OutputToken("Error returned by AuthenticateAsync() : " + WebAuthenticationResult.ResponseStatus.ToString()); } }
public async Task<OAuthAccessToken> GetOAuthAccessTokenAsync(System.Threading.CancellationToken cancelToken) { var helper = new OAuth2Helper(OAuthSettings); OAuthAccessToken accessToken = null; switch (GrantType) { case GrantType.AuthorizationCode: accessToken = await helper.GetAccessTokenByCodeAsync(AuthorizationCode); break; case GrantType.Password: accessToken = await helper.GetAccessTokenByPasswordAsync(Passport, Password); break; default: accessToken = await helper.LoginAsync(Passport, Password, cancelToken); break; } return accessToken; }
public async Task <OAuthAccessToken> GetOAuthAccessTokenAsync(System.Threading.CancellationToken cancelToken) { var helper = new OAuth2Helper(OAuthSettings); OAuthAccessToken accessToken = null; switch (GrantType) { case GrantType.AuthorizationCode: accessToken = await helper.GetAccessTokenByCodeAsync(AuthorizationCode); break; case GrantType.Password: accessToken = await helper.GetAccessTokenByPasswordAsync(Passport, Password); break; default: accessToken = await helper.LoginAsync(Passport, Password, cancelToken); break; } return(accessToken); }