I realized that this is absolutely wrong. First, I really need to use the app.UseJwtBearerAuthentication method. An example was found here http://code.lawrab.com/2014/01/securing-webapi-with-live-id.html . But when I tried, I got this error on output
IDX10500: Signature validation failed. Unable to resolve SecurityKeyIdentifier: 'SecurityKeyIdentifier ( IsReadOnly = False, Count = 1, Clause[0] = System.IdentityModel.Tokens.NamedKeySecurityKeyIdentifierClause )
It took me a while until I found this post: JwtSecurityTokenHandler 4.0.0 Breaking changes?
Combining these things, I got a solution that now works in my test environment:
public void ConfigureAuth(IAppBuilder app) { var sha256 = new SHA256Managed(); var sKey = "<Secret key>" + "JWTSig"; var secretBytes = new UTF8Encoding(true, true).GetBytes(sKey); var signingKey = sha256.ComputeHash(secretBytes); var securityKeyProvider = new SymmetricKeyIssuerSecurityTokenProvider("urn:windows:liveid", signingKey); var securityKey = securityKeyProvider.SecurityTokens.First().SecurityKeys.First(); var jwtOptions = new JwtBearerAuthenticationOptions() { //AllowedAudiences = new[] { "<url>" }, //IssuerSecurityTokenProviders = new[] //{ // new SymmetricKeyIssuerSecurityTokenProvider("urn:windows:liveid",signingKey) //}, TokenValidationParameters = new System.IdentityModel.Tokens.TokenValidationParameters() { IssuerSigningKeyResolver = (token, securityToken, keyIdentifier, validationParameters) => { return securityKey; }, ValidAudience = "<url>", ValidIssuer = securityKeyProvider.Issuer } }; app.UseJwtBearerAuthentication(jwtOptions); }
source share