Esempio n. 1
0
        /// <summary>
        /// Continues the authenticate user flow by extracting results from the Windows-specific
        /// auth method and moving on to the final common step.
        /// </summary>
        /// <param name="authResult">The result from the WebAuthenticationBroker call.</param>
        /// <returns>
        /// Whether the token was retrieved
        /// </returns>
        internal async Task <Response <AuthResultCode> > ConvertAuthPermissionParams(WebAuthenticationResult authResult)
        {
            try
            {
                switch (authResult.ResponseStatus)
                {
                case WebAuthenticationStatus.Success:

                    // ResponseData will give us the final URI with a Querystring containing an auth code or error details
                    // e.g. code=90e754fd-0a4a-4eb5-b5f6-25dad9face6a or error=access_denied
                    AuthResultCode resultCode        = AuthResultCode.Unknown;
                    string         authorizationCode = null;

                    OAuthResultParser.ParseQuerystringForCompletedFlags(authResult.ResponseData, out resultCode, out authorizationCode);
                    if (resultCode != AuthResultCode.Unknown)
                    {
                        // Move on to obtain a token
                        return(await this.ObtainToken(authorizationCode, null, resultCode));
                    }
                    else
                    {
                        return(new Response <AuthResultCode>(null, AuthResultCode.Unknown, Guid.Empty));
                    }

                case WebAuthenticationStatus.ErrorHttp:
                    switch ((HttpStatusCode)authResult.ResponseErrorDetail)
                    {
                    case HttpStatusCode.BadRequest:
                        return(new Response <AuthResultCode>(null, AuthResultCode.InvalidScope, Guid.Empty));

                    case HttpStatusCode.Unauthorized:
                        return(new Response <AuthResultCode>(null, AuthResultCode.UnauthorizedClient, Guid.Empty));

                    case HttpStatusCode.InternalServerError:
                        return(new Response <AuthResultCode>(null, AuthResultCode.ServerError, Guid.Empty));
                    }

                    // Any other items will return as cancelled below...
                    break;
                }
            }
            catch
            {
                // Usually means we got cancelled
            }

            return(new Response <AuthResultCode>(null, AuthResultCode.Cancelled, Guid.Empty));
        }
Esempio n. 2
0
        private void Browser_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            string query = e.Url.Query;
#endif
            if (!string.IsNullOrEmpty(query))
            {
                AuthResultCode result = AuthResultCode.Unknown;
                string authorizationCode = null;

                if (OAuthResultParser.ParseQuerystringForCompletedFlags(query, out result, out authorizationCode))
                {
                    if (result == AuthResultCode.Success)
                    {
                        this.AuthorizationCode = authorizationCode;
                    }
                    
                    this.ResultCode = result;
                    e.Cancel = true;
                    this._authWaiter.Set();
                }
            }
        }