public ClaimsPrincipal ValidateApiKey(ApiKeyValidationContext context, string apiKey, out ValidatedApiKey validatedApiKey)
        {
            ApiKeyInfo info;

            if (context.ApiKeys.TryGetValue(apiKey, out info))
            {
                validatedApiKey = new ValidatedApiKey();
                return(new ClaimsPrincipal(new ClaimsIdentity(info.Claims, context.Options.AuthenticationScheme)));
            }
            throw new ApiKeyNotFoundException()
                  {
                      ApiKey = apiKey
                  };
        }
Exemplo n.º 2
0
        public ClaimsPrincipal ValidateApiKey(ApiKeyValidationContext context, string apiKey, out ValidatedApiKey validatedApiKey)
        {
            validatedApiKey = new ValidatedApiKey();
            _tokenValidator?.Invoke(apiKey);
            var claims = new[]
            {
                // Make sure to use a different name identifier
                // than the one defined by CustomTokenValidated.
                new Claim(ClaimTypes.NameIdentifier, "Bob le Tout Puissant"),
                new Claim(ClaimTypes.Email, "*****@*****.**"),
                new Claim(ClaimsIdentity.DefaultNameClaimType, "bob"),
            };

            return(new ClaimsPrincipal(new ClaimsIdentity(claims, context.Options.AuthenticationScheme)));
        }
 public ClaimsPrincipal ValidateApiKey(ApiKeyValidationContext context, string apiKey, out ValidatedApiKey validatedApiKey)
 {
     if (errorType != null)
     {
         var err = (Exception)Activator.CreateInstance(errorType);
         throw err;
     }
     throw new Exception();
 }