简体   繁体   中英

Check token validity from startup.cs

I have multiple API's and one of them allow token authentication, the controller of the authentication api generate a token, and what I want is check the validity of this token from the startup.cs of the other API's.

Anyone has an idea how to do it corretly?

Here is my startup.cs where I want to check the recieved token:

 //Add JWT
services.AddAuthentication(options => {
  options.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;})
    .AddJwtBearer(options => {
      options.RequireHttpsMetadata = false;
      options.MetadataAddress = "http://localhost:50214/api/Authentification/Validate";
      options.SaveToken = true;
   });

The Jwt middleware itself is perfectly happy to perform validation. What you may be interested in doing is reacting to one or more of the events that the middleware exposes, such as OnMessageReceived (a "raw" way of interacting with the protocol and making modifications) or OnTokenValidated (which happens after rather then before validation has occurred).

These are attached to the JwtBearerEvents class which can be accessed from your code via options.Events .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM