Esempio n. 1
0
        /// <summary>
        /// This Method is to Autheticate state using Refresh Token
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        private IAuthorizationState Authenticatestate(WebServerClient client)
        {
            IAuthorizationState state = new AuthorizationState(new string[] { })
            {
                RefreshToken = txtRefreshToken.Text
            };

            client.RefreshToken(state);
            return(state);
        }
Esempio n. 2
0
    private static IAuthorizationState Authenticate(WebServerClient client)
    {
        IAuthorizationState state = new AuthorizationState(new string[] {})
        {
            RefreshToken = "REFRESH_TOKEN"
        };

        client.RefreshToken(state);
        return(state);
    }
        /// <summary>
        /// Gets the authorization object for the client-side flow.
        /// </summary>
        /// <param name="client">The client used for authorization.
        /// </param>
        /// <returns>An authorization state that can be used for API queries.
        /// </returns>
        protected IAuthorizationState GetAuthorization(WebServerClient client)
        {
            // If we don't yet have user, use the client to perform
            // authorization.
            if (_authState != null)
            {
                HttpRequestInfo reqinfo = null;
                if (_httpReqMethod != null && _reqUri != null && _rawUrl != null &&
                    _headers != null && _inputStream != null)
                {
                    reqinfo = new HttpRequestInfo(_httpReqMethod, _reqUri, _rawUrl,
                                                  (System.Net.WebHeaderCollection)_headers, _inputStream);
                }

                if (reqinfo == null)
                {
                    reqinfo = new HttpRequestInfo(HttpContext.Current.Request);
                }
                client.ProcessUserAuthorization(reqinfo);
            }

            // Check for a cached session state.
            if (_authState == null)
            {
                _authState = (IAuthorizationState)HttpContext.Current.
                             Session["AUTH_STATE"];
            }

            // Check if we need to refresh the authorization state and refresh
            // it if necessary.
            if (_authState != null)
            {
                if (_authState.RefreshToken.IsNotNullOrEmpty() && (_authState.AccessToken == null ||
                                                                   DateTime.UtcNow > _authState.AccessTokenExpirationUtc))
                {
                    client.RefreshToken(_authState);
                }
                return(_authState);
            }

            // If we fall through to here, perform an authorization request.
            OutgoingWebResponse response =
                client.PrepareRequestUserAuthorization();

            response.Send();
            // Note: response.send will throw a ThreadAbortException to
            // prevent sending another response.
            return(null);
        }
Esempio n. 4
0
        // GetAuthorization
        /// <summary>
        /// Gets the authorization object for the client-side flow.
        /// </summary>
        /// <param name="client">The client used for authorization.
        /// </param>
        /// <returns>An authorization state that can be used for API queries.
        /// </returns>
        private IAuthorizationState GetAuthorization(WebServerClient client)
        {
            // If we don't yet have user, use the client to perform
            // authorization.
            if (_authState != null)
            {
                HttpRequestInfo reqinfo =
                    new HttpRequestInfo(HttpContext.Current.Request);
                client.ProcessUserAuthorization(reqinfo);
            }

            // Check for a cached session state.
            if (_authState == null)
            {
                _authState = (IAuthorizationState)HttpContext.Current.
                             Session["AUTH_STATE"];
            }

            // Check if we need to refresh the authorization state and refresh
            // it if necessary.
            if (_authState != null)
            {
                if (_authState.AccessToken == null ||
                    DateTime.UtcNow > _authState.AccessTokenExpirationUtc)
                {
                    client.RefreshToken(_authState);
                }
                return(_authState);
            }

            // If we fall through to here, perform an authorization request.
            OutgoingWebResponse response =
                client.PrepareRequestUserAuthorization(_authState.Scope);

            response.Send();
            // Note: response.send will throw a ThreadAbortException to
            // prevent sending another response.
            return(null);
        }