Giter Club home page Giter Club logo

dotnet-jwt-test's Introduction

Another sandbox project

This one is to test how authentication works when using JWTs as auth method. My main curiosity was how loose JWTs get validated.

JWT validation

I've tested this by using a keycloak OIDC authority. Using the following command, you can generate a JWT token for a keycloak user:

curl -L -X POST https://<keycloak url>/realms/<realm name>/protocol/openid-connect/token \
    -H 'Content-Type: application/x-www-form-urlencoded' \
    --data-urlencode 'client_id=<client id>' \
    --data-urlencode 'grant_type=password' \
    --data-urlencode 'client_secret=<client secret>' \
    --data-urlencode 'scope=openid' \
    --data-urlencode 'username=<username>' \
    --data-urlencode 'password=<password>' | \
    jq -r .access_token

Additionally, configure OIDC:Authority in your secrets or in appsettings.json.

Then, run the "weather forecast" service and test authentication as follows:

curl -v -H "Authorization: Bearer <JWT>" http://localhost:5165/WeatherForecast

The first time an authentication request is made, the application will request https://<keycloak url>/realms/<realm name>/protocol/openid-connect/certs which contains the public keys of the issued JWT. I'm not sure if it's being cached for a certain time or for the remainder of the application runtime, but subsequent calls to the weather forecast service will not trigger the request again. I would find it logical that it's only being cached for a certain time.

The certs URL mentioned above is coming from the OpenID configuration. Before the certs call, https://<keycloak url>/realms/<realm name>/.well-known/openid-configuration is retrieved to determine the URL configured in jwks_uri, which in case of keycloak is the /certs url. The /certs URL returns a JSON struct defined in RFC7517.
This flow is also explained on this auth0 page.

dotnet-jwt-test's People

Contributors

friek avatar dependabot[bot] 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.