I am porting an ASP.NET Web API 4.6 OWIN
application to ASP.NET Core 2.1
. The application is working based on JWT
token. But the token in passed via cookie instead of header. I'm not sure why headers are not used, it is just the situation that I have to deal with.
Consider that authentication is not done via cookie. The cookie is just used as a transfering media. In the legacy application CookieOAuthBearerProvider
is employed to extract JWT
token from cookie. Configuration code is as like this:
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
AllowedAudiences = new[] { audienceId },
IssuerSecurityTokenProviders = new IIssuerSecurityTokenProvider[]
{
new SymmetricKeyIssuerSecurityTokenProvider(issuer, audienceSecret)
},
Provider = new CookieOAuthBearerProvider("token")
});
}
CookieOAuthBearerProvider
class source source code is as follow:
public class CookieOAuthBearerProvider : OAuthBearerAuthenticationProvider
{
readonly string _name;
public CookieOAuthBearerProvider(string name)
{
_name = name;
}
public override Task RequestToken(OAuthRequestTokenContext context)
{
var value = context.Request.Cookies[_name];
if (!string.IsNullOrEmpty(value))
{
context.Token = value;
}
return Task.FromResult<object>(null);
}
This solution is discussed here with more detail.
Now I need to implement similar solution for ASP.NET Core. Problem is that UseJwtBearerAuthentication
does not exists in ASP.NET Core
anymore and I do not know how I can introduce a custom AuthenticationProvider.
Any helps is highly appreciated.
UPDATE: There is a solution that tries to validate JWT by its own code. It is not what I need. I'm just searching for a way to pass token recieved from cookie to header reader.