OpenID Connect Sample with Signature Verification

ID tokens are used in OpenID Connect to sign in users into client apps. But how to validate them?
Like identity cards, they contain a number of attributes or claims. These are protected with a digital signature, or message authentication code (MAC), to ensure the token’s integrity and authenticity.
ID tokens carry the following claims:
  • Subject (sub) — identifier for the authenticated user
  • Issuer (iss) and audience (aud) — specify the IdP that created the ID token and who it is intended for (the client_id)
  • Timestamps - issue (iat) and expiration (exp) times
  • Other attributes, such as authentication time, strength, a nonce, and selected user details can also be included.

So, I'm going to discuss how to verify the signature of ID token with sample web application. This is an improved version of the previous app. When it comes to validate an ID Token, an app wants to verify the signature of the token, as well as validate the standard claims.

The signature is used to prove whether the sender of the token is who it says it is and to ensure that the message wasn’t changed along the way. ID Token is always a JWT, and the signature is created using its header and payload, a secret and the hashing algorithm is used.

Validate the Claims

Once the token's signature is verified by the application, the next step is to validate the standard claims of the token’s payload. It will make sure whether the appropriate claims were received or not. So, the following claims will be validated.

  • Token expiration
  • Token issuer
  • Token audience
Once you download and run the web app access it on

Then click on Login with miniOrange and give following credentials. You may use your own client app, then give those credentials.

So this web app verifies the signature and shows as follows.

This is the code segment which is used to validate the ID token.

For the verification of the signature, this web app needs the public key of the OIDC provider. You can download it from miniOrange.

When the certificate is placed to the file input steam it will run against the ID token which is available and verify whether it is valid or not. Here it will check the claims as ID token issuer. That’s the reason for looking for the claim “iss”.

If the token is not valid it will throw an exception showing token verification is failed. The situation is shown as follows when the verification is failed.

Comments

Popular posts from this blog

How to hack windows 2000 using nessus.....

OpenID Connect Introduction

Crypt-analysis