# region registration certification service
Services. AddAuthentication (options=& gt;
{
Options. DefaultAuthenticateScheme=JwtBearerDefaults. AuthenticationScheme;
Options. DefaultChallengeScheme=JwtBearerDefaults. AuthenticationScheme;
})
AddJwtBearer (o=& gt;
{
O.T okenValidationParameters=new TokenValidationParameters
{
ValidIssuer="Issuer",
ValidAudience="on",
IssuerSigningKey=new SymmetricSecurityKey (Encoding UTF8. GetBytes (" JwtAuth: SecurityKey ")),
RequireSignedTokens=true,
ValidateAudience=false,
ValidateIssuer=true,
ValidateIssuerSigningKey=true,
RequireExpirationTime=true,
ClockSkew=TimeSpan. FromSeconds (300),
ValidateLifetime=true
};
});
# endregion
Configure:
App. UseAuthentication (.) UseMvc ();
Controller:
[the Authorize (AuthenticationSchemes=JwtBearerDefaults AuthenticationScheme, Policy="XXXXX")]
Public class XXXController: Controller
{
//do...
}
Such function is normal, but the controller of the
AuthenticationSchemes=JwtBearerDefaults. AuthenticationSchemeremove will authentication failure, before the same writing didn't add this project, why do we need to add this now? Carefully looked at the console output info, do not add a displayed using the default authentication to certification, the results failed, and displayed after using JwtBearer certification success (only for the first time, after another call will display the default authentication succeeded), don't know where is the problem, the feeling is not set to? Reference about this https://stackoverflow.com/questions/51263883/webapi-authorize-attribute-with-services-addidentity-returns-404-not-found says, but also can't understand, hope god give directions,
The last hope that we can recommend some certification process to introduce articles)
CodePudding user response:
Well,,, no,,,,CodePudding user response:
https://mp.weixin.qq.com/s/9F90xa61n3RS_qfbPxomdw