Ejemplo n.º 1
0
        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());
            }
        }