Пример #1
0
        private async Task CreateAuthenticationTicket(AuthenticationTokenReceiveContext context)
        {
            var token = await this.options.TokenManager.FindAccessTokenAsync(context.Token);

            OAuthValidateTokenContext <IAccessToken> validateContext = new OAuthValidateTokenContext <IAccessToken>(
                context.OwinContext, options, context, token);

            await options.TokenProvider.ValidateAccessToken(validateContext);

            if (validateContext.IsValidated)
            {
                context.DeserializeTicket(token.Ticket);
            }

            //var identity = await options.TokenManager.AuthenticateAccessTokenAsync(context.Token);
            //if (identity.IsAuthenticated)
            //{

            //    var props = new AuthenticationProperties
            //    {
            //        ExpiresUtc = DateTimeOffset.UtcNow.Add(this.options.AccessTokenLifetime)
            //    };

            //    if (identity.HasClaim(x => x.Type == Constants.ClaimType.Client))
            //    {
            //        props.Dictionary.Add("client_id", identity.Claims.First(x => x.Type == Constants.ClaimType.Client).Value);
            //    }

            //    return new AuthenticationTicket(identity, props);
            //}
            //else
            //{
            //    return null;
            //}
        }
Пример #2
0
        public async Task ValidateAccessToken(OAuthValidateTokenContext <IAccessToken> context)
        {
            var result = new TokenValidationResult <IAccessToken>(context.Token);

            if (context.Token == null || string.IsNullOrWhiteSpace(context.Token.Ticket))
            {
                context.Rejected();
                return;
            }
            context.Validated();
        }
Пример #3
0
 public async Task ValidateRefreshToken(OAuthValidateTokenContext <IRefreshToken> context)
 {
     if (!string.IsNullOrWhiteSpace(context.AuthenticationTokenReceiveContext.Token) && context.Token != null)
     {
         context.Validated();
     }
     else
     {
         context.Rejected();
     }
 }