Skip to content

mcorso21/AuthService

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Auth Services

Using this Library


JSON Web Token (JWT) Service

  1. Ensure JWTService.UpdateSecretKey is pulling the SecretKey from the correct location, it defaults to looking in App.config:
    secretKey = ConfigurationManager.AppSettings.Get("SecretKey");
  2. Create an instance of JWTService
    JWTService jwtService = new JWTService();
  3. Generate a JWT
    string token = jwtService.GenerateToken(new Claim[] { new Claim(ClaimTypes.Email, "name@gmail.com") });
  4. Validate a JWT
    bool isValid = jwtService.IsTokenValid(token);
  5. Get the claims in a JWT
    // Get the tokens
    var jwtClaims = jwtService.GetTokenClaims(token);
    // Get a specific value
    string email = "";
    email = jwtClaims.Where(x => x.Type.Equals(ClaimTypes.Email.ToString())).FirstOrDefault().Value;
    // Iterate through the tokens
    long expiration= 0;
    foreach(Claim claim in jwtClaims)
    {
        if(claim.Type.Equals("exp"))
            expiration = long.Parse(claim.Value);
        else if (claim.Type.Equals(ClaimTypes.Email.ToString()))
            email = claim.Value;
    }

About

Simple Auth Service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages