Example #1
0
        private async Task AccessTokenAndCachedTokenMisMatch(HttpContext context, string cachedToken, string accessToken)
        {
            var otherInfo = "Cached Token :" + cachedToken + "~ Access Token :" + accessToken;

            _logger.CustomInformation(user: "******", other: otherInfo, informationMessage: "Mismatch in Access Token And Cached Token");

            _oauthCache.ResetCache();

            var response = _oauthClient.GetUserInfo(accessToken);

            // Invalid Request
            if (response != null)
            {
                _oauthCache.SetAccessToken(accessToken, 50);
                _logger.CustomInformation(informationMessage: "Handling Authentication Handler Finished.");
                SetUserDetails(context);
                await _next.Invoke(context);
            }
            else
            {
                await UnAuthorizedResponseToClient(context, ErrorMessages.ErrorMessageKey.InvalidAccessToken, 500);
            }
        }
Example #2
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            var cachedAccessToken = _ouathCache.GetAccessToken(filterContext.HttpContext);

            if (string.IsNullOrWhiteSpace(cachedAccessToken))
            {
                var tokenEndpointResponse = _ouathClient.GetAccessToken();

                if (string.IsNullOrWhiteSpace(tokenEndpointResponse.Error))
                {
                    _ouathCache.SetAccessToken(filterContext.HttpContext, tokenEndpointResponse.AccessToken, 50);
                    SetAccessTokenInRouteData(filterContext, tokenEndpointResponse.AccessToken);
                }
                else
                {
                    // Drop an Email. Not able to connect to Oauth Server.
                    // Log into database.
                }
            }
            else
            {
                SetAccessTokenInRouteData(filterContext, cachedAccessToken);
            }
        }