/// <summary>
        /// Revoke token using either access or refresh token
        /// </summary>
        /// <param name="revokeTokenEndpoint"></param>
        /// <param name="accessOrRefreshToken"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <TokenRevocationResponse> RevokeTokenAsync(string revokeTokenEndpoint, string accessOrRefreshToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(revokeTokenEndpoint))
            {
                AdvancedLogger.Log("Revoke Token Endpoint is empty.");
                return(new TokenRevocationResponse(HttpStatusCode.InternalServerError, "Revoke Token Endpoint is empty."));
            }

            AdvancedLoggerEnabled = true;
            //Set internal property to track only informational -intuit_tid based logs
            if (EnableAdvancedLoggerInfoMode == true)
            {
                ShowInfoLogs = true;
            }
            //Intialize Logger
            AdvancedLogger = LogHelper.GetAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: this.EnableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: this.EnableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: this.EnableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForRollingFile: this.EnableSerilogRequestResponseLoggingForRollingFile, serviceRequestLoggingLocationForFile: this.ServiceRequestLoggingLocationForFile);



            TokenRevocationClient revokeTokenClient = new TokenRevocationClient(revokeTokenEndpoint, ClientID, ClientSecret);

            return(await revokeTokenClient.RevokeAsync(new TokenRevocationRequest
            {
                Token = accessOrRefreshToken,
            }, cancellationToken).ConfigureAwait(false));
        }
예제 #2
0
        /// <summary>
        /// Get User Info
        /// </summary>
        /// <param name="userInfoEndpoint"></param>
        /// <param name="accessToken"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <UserInfoResponse> GetUserInfoAsync(string userInfoEndpoint, string accessToken, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(userInfoEndpoint))
            {
                AdvancedLogger.Log("UserInfo Endpoint is empty.");
                return(new UserInfoResponse(HttpStatusCode.InternalServerError, "UserInfo Endpoint is empty."));
            }

            AdvancedLoggerEnabled = true;
            //Set internal property to track only informational -intuit_tid based logs
            if (EnableAdvancedLoggerInfoMode == true)
            {
                ShowInfoLogs = true;
            }

            if (this.CustomLogger != null)
            {
                //Use custom logger
                AdvancedLogger = LogHelper.GetAdvancedLoggingCustom(this.CustomLogger);
            }
            else
            {
                //Intialize Logger
                AdvancedLogger = LogHelper.GetAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: this.EnableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: this.EnableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: this.EnableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForFile: this.EnableSerilogRequestResponseLoggingForFile, serviceRequestLoggingLocationForFile: this.ServiceRequestLoggingLocationForFile);
            }


            UserInfoClient userInfoClient = new UserInfoClient(userInfoEndpoint);

            return(await userInfoClient.GetAsync(accessToken, cancellationToken).ConfigureAwait(false));
        }
예제 #3
0
        /// <summary>
        /// Refreshes access token to get new access token
        /// </summary>
        /// <param name="refreshToken"></param>
        /// <param name="extra"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <TokenResponse> RefreshTokenAsync(string refreshToken, object extra = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(DiscoveryDoc.TokenEndpoint))
            {
                AdvancedLogger.Log("Discovery Call failed. RefreshToken Endpoint is empty.");
                return(new TokenResponse(HttpStatusCode.InternalServerError, "Discovery Call failed. RefreshToken Endpoint is empty."));
            }

            AdvancedLoggerEnabled = true;
            //Set internal property to track only informational -intuit_tid based logs
            if (EnableAdvancedLoggerInfoMode == true)
            {
                ShowInfoLogs = true;
            }

            if (this.CustomLogger != null)
            {
                //Use custom logger
                AdvancedLogger = LogHelper.GetAdvancedLoggingCustom(this.CustomLogger);
            }
            else
            {
                //Intialize Logger
                AdvancedLogger = LogHelper.GetAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: this.EnableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: this.EnableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: this.EnableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForFile: this.EnableSerilogRequestResponseLoggingForFile, serviceRequestLoggingLocationForFile: this.ServiceRequestLoggingLocationForFile);
            }

            var tokenClient = new TokenClient(DiscoveryDoc.TokenEndpoint, ClientID, ClientSecret);

            return(await tokenClient.RequestRefreshTokenAsync(refreshToken, cancellationToken).ConfigureAwait(false));
        }
        /// <summary>
        /// Gets the Request Response Logging mechanism for advanced logging using serilog.
        /// </summary>
        /// <returns>Returns value which specifies the request response logging mechanism.</returns>
        public static OAuthAdvancedLogging GetAdvancedLogging(bool enableSerilogRequestResponseLoggingForDebug, bool enableSerilogRequestResponseLoggingForTrace, bool enableSerilogRequestResponseLoggingForConsole, bool enableSerilogRequestResponseLoggingForRollingFile, string serviceRequestLoggingLocationForFile)
        {
            OAuthAdvancedLogging advancedLogger;

            advancedLogger = new OAuthAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: enableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: enableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: enableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForRollingFile: enableSerilogRequestResponseLoggingForRollingFile, serviceRequestLoggingLocationForFile: serviceRequestLoggingLocationForFile);

            return(advancedLogger);
        }
예제 #5
0
        /// <summary>
        /// Get Authorization Url
        /// </summary>
        /// <param name="scopes"></param>
        /// <returns></returns>
        public string GetAuthorizationURL(List <OidcScopes> scopes)
        {
            if (string.IsNullOrEmpty(DiscoveryDoc.AuthorizeEndpoint))
            {
                throw new System.Exception("Discovery Call failed. Authorize Endpoint is empty.");
            }

            AdvancedLoggerEnabled = true;
            //Set internal property to track only informational -intuit_tid based logs
            if (EnableAdvancedLoggerInfoMode == true)
            {
                ShowInfoLogs = true;
            }

            if (this.CustomLogger != null)
            {
                //Use custom logger
                AdvancedLogger = LogHelper.GetAdvancedLoggingCustom(this.CustomLogger);
            }
            else
            {
                //Intialize Logger
                AdvancedLogger = LogHelper.GetAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: this.EnableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: this.EnableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: this.EnableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForFile: this.EnableSerilogRequestResponseLoggingForFile, serviceRequestLoggingLocationForFile: this.ServiceRequestLoggingLocationForFile);
            }



            string scopeValue = "";

            for (var index = 0; index < scopes.Count; index++)
            {
                scopeValue += scopes[index].GetStringValue() + " ";
            }
            scopeValue = scopeValue.TrimEnd();

            //creating CSRF token since client did not send one
            CSRFToken = GenerateCSRFToken();

            //builiding authorization request
            string authorizationRequest = string.Format("{0}?client_id={1}&response_type=code&scope={2}&redirect_uri={3}&state={4}",
                                                        DiscoveryDoc.AuthorizeEndpoint,
                                                        ClientID,
                                                        Uri.EscapeDataString(scopeValue),
                                                        Uri.EscapeDataString(RedirectURI),
                                                        CSRFToken);

            //Logging authorization request
            AdvancedLogger.Log("Logging AuthorizationRequest:" + authorizationRequest);

            return(authorizationRequest);
        }
        /// <summary>
        /// Gets Bearer token from Authorization code and manually passing Bearer Token url
        /// </summary>
        /// <param name="tokenEndpoint"></param>
        /// <param name="code"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <TokenResponse> GetBearerTokenAsync(string tokenEndpoint, string code, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(tokenEndpoint))
            {
                AdvancedLogger.Log("BearerToken Endpoint is empty.");
                return(new TokenResponse(HttpStatusCode.InternalServerError, "BearerToken Endpoint is empty."));
            }

            AdvancedLoggerEnabled = true;
            //Set internal property to track only informational -intuit_tid based logs
            if (EnableAdvancedLoggerInfoMode == true)
            {
                ShowInfoLogs = true;
            }
            //Intialize Logger
            AdvancedLogger = LogHelper.GetAdvancedLogging(enableSerilogRequestResponseLoggingForDebug: this.EnableSerilogRequestResponseLoggingForDebug, enableSerilogRequestResponseLoggingForTrace: this.EnableSerilogRequestResponseLoggingForTrace, enableSerilogRequestResponseLoggingForConsole: this.EnableSerilogRequestResponseLoggingForConsole, enableSerilogRequestResponseLoggingForRollingFile: this.EnableSerilogRequestResponseLoggingForRollingFile, serviceRequestLoggingLocationForFile: this.ServiceRequestLoggingLocationForFile);



            var tokenClient = new TokenClient(tokenEndpoint, ClientID, ClientSecret);

            return(await tokenClient.RequestTokenFromCodeAsync(code, RedirectURI, cancellationToken : cancellationToken).ConfigureAwait(false));
        }