Giter Club home page Giter Club logo

azure-jwt-verify's Introduction

azure-jwt-verify

npm version License: MIT

This Plugin Requires

  • NodeJS Runtime

Features

  • Verify JWT Token issued by Azure Active Directory B2C
  • Automatically use the rotated public key from Azure Public Keys URL

Install Plugin

npm install --save azure-jwt-verify

Using Azure JWT Verify in your code

You need to define the following constants based on your Azure Active Directory B2C application configurations

Initialize module

var azureJWT = require('azure-jwt-verify');

Configuration and the JWT to verify

var jwtToken = "YOUR_JWT_TOKEN_TO_VERIFY"; // You can find this url in Azure Active Directory B2C Section
const config = {
    JWK_URI: "",
    ISS: "",
    AUD: ""
};
  • JWK_URI and the ISS(Issuer) can be obtained from the metadata endpoint of the policies created in the B2C tenant.
  • AUD(Audience) is the Client ID of the application accessing the tenant.

Verify Function

azureJWT.verify(jwtToken, config).then(function(decoded){
// success callback

}, function(error){
// error callback

})

Response Examples

For valid and authorize JWT token.

Response body:

{
   "status": "success",
   "message": {
      "exp": 1486111778,
      "nbf": 1486108178,
      "ver": "1.0",
      "iss": "https://login.microsoftonline.com/9434db1e-33cd-4607-b350-9d947127a5de/v2.0/",
      "sub": "ff8490cb-2bda-4cc8-b801-4a22a8620c59",
      "aud": "dfc54797-efe3-4db3-a1e1-422b4ecf27d7",
      "nonce": "defaultNonce",
      "iat": 1486108178,
      "auth_time": 1486108178,
      "oid": "ff8490cb-2bda-4cc8-b801-4a22a8620c59",
      "name": "jon snow",
      "extension_NIC": "933132325V",
      "emails": [
         "[email protected]"
      ],
      "tfp": "B2C_1_b2c_1_sign_in"
   }
}

For valid but expired JWT token.

Response body:

{
   "status": "error",
   "message": {
      "name": "TokenExpiredError",
      "message": "jwt expired",
      "expiredAt": "2017-02-02T12:30:11.000Z"
   }
}

For invalid JWT token.

Response body:

{
   "status": "error",
   "message": "Error Decoding JWT Token"
}

Links

License

MIT

azure-jwt-verify's People

Contributors

alangford avatar ashanfernando avatar chamathpali avatar chamathsilva avatar kristiankielhofner avatar panuhorsmalahti avatar rehrumesh avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.