Пример #1
0
        private async Task AccessTokenProvidedByClientApplication(HttpContext context, string accessToken)
        {
            var cachedToken = _oauthCache.GetAccessToken();

            if (cachedToken.Equals(accessToken))
            {
                _logger.CustomInformation(informationMessage: "user logged successfully");

                await _next.Invoke(context);
            }
            else
            {
                await AccessTokenAndCachedTokenMisMatch(context, cachedToken, accessToken);
            }
        }
Пример #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);
            }
        }