GithubHelp home page GithubHelp logo

sungho-choo / jwtexample Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mauritsderuiter95/jwtexample

0.0 0.0 0.0 9 KB

Example code for https://medium.com/swlh/a-secure-implementation-of-json-web-tokens-jwt-in-c-710d06ea243

C# 100.00%

jwtexample's Introduction

JWT Example code

This is example code for A secure implementation of JSON Web Tokens (JWT) in C#.

Warning: This is very basic and doesn't do things like hashing passwords! Only to test JSON Web Tokens.

To test this, you need to have Dotnet Core 3 and MongoDB installed. Settings are in appsettings.json.

This uses the following packages:

After restoring the packages and starting it, do the following to test the JWT:

  1. POST https://localhost:5001/users with the following body:
{
    "username": "yourusername",
    "password": "yourpassword"
}
  1. POST https://localhost:5001/tokens/accesstoken with the same body. You get the following response:
{
    "accessToken": "*jwt*",
    "refreshToken": "*jwt*"
}
  1. To test the access token do a GET request to https://localhost:5001/users. In the Authorization header of the request should be "Bearer " and then the access token you got in step 2. It will give you a response with the user you created in step 1.

  2. To test the refresh token do a PUT request to https://localhost:5001/tokens/accesstoken. In the Authorization header of the request should be "Bearer " and then the refresh token you got in step 2. It should respond with a new access token and a new refresh token. Try again to test if the refresh token is deleted, which it should.

jwtexample's People

Contributors

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