Example #1
0
 public override Task ValidateIdentity(OAuthValidateIdentityContext context)
 {
     var claims = context.Ticket.Identity.Claims;
     if (claims.Count() == 0 || claims.Any(claim => claim.Issuer != "Facebook" && claim.Issuer != "LOCAL_AUTHORITY"))
         context.Rejected();
     return Task.FromResult<object>(null);
 }
        public override Task ValidateIdentity(OAuthValidateIdentityContext context)
        {
            if (context.Ticket.Properties.ExpiresUtc < DateTime.UtcNow)
            {
                context.SetError("invalid_grant", "Access Token has expired.");
                context.Rejected();
                return ThreadingExtensions.NoResult;
            }

            var userId = context.Ticket.Identity.GetUserGuid();
            var issuedGuid = context.Ticket.Properties
                .GetIssuedGuid();

            if (!_authKeyRepository.ValidateAuthKey(userId, issuedGuid))
            {
                context.SetError("invalid_token", "Access Token has not been properly set or has been invalidated.");
                context.Rejected();
                return ThreadingExtensions.NoResult;
            }

            context.Validated();
            return ThreadingExtensions.NoResult;
        }
        public override System.Threading.Tasks.Task ValidateIdentity(OAuthValidateIdentityContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.Ticket.Identity.Claims.Any(c => c.Issuer != "LOCAL AUTHORITY"))
            {
                context.Rejected();
            }

            return Task.FromResult<object>((object)null);
        }
        public override Task ValidateIdentity(OAuthValidateIdentityContext context)
        {
            bool validated = false;
            base.ValidateIdentity(context);
            ApplicationDbContext dbContext = context.OwinContext.Get<ApplicationDbContext>();
            ApplicationUserManager userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();

            if(context.Ticket!= null && context.Ticket.Identity != null)
            {
                if(context.Ticket.Identity.Claims.SingleOrDefault(c => c.Type == OAuthClientCredentialsGrantKey) != null)
                {
                    Guid clientId = new Guid(context.Ticket.Identity.Name);
                    if (dbContext.OAuthClients.SingleOrDefault(oac => oac.ClientId == clientId && oac.Enabled==true) != null)
                    {
                        validated = true;
                        context.Validated();
                    }
                }
                else {
                    Claim oauthSessionId = context.Ticket.Identity.Claims.SingleOrDefault(c => c.Type == OAuthSessionClaimKey);
                    if (oauthSessionId != null)
                    {
                        OAuthSession oauthSession = dbContext.OAuthSessions.SingleOrDefault(oas => oas.Id.ToString() == oauthSessionId.Value);
                        if (oauthSession != null)
                        {
                            validated = true;
                            context.Validated();
                        }
                    }
                }
            }
            if (!validated)
            {
                context.SetError("Invalid Token", "The Access Token is invalid.");
                context.Rejected();
            }
            return Task.FromResult<object>(null);
        }