Code Monkey home page Code Monkey logo

rdlabauthdemo's Introduction

Small demo to show how Jwt, OAuth works

RDLabAuthDemo.BasicJwt

  1. Set required variables.
  • init local secrets store
  • navigate to src\RDLabAuthDemo.BasicJwt directory and execute:
dotnet user-secrets init
  • set values for each value
dotnet user-secrets set "JwtToken:Key" "YOUR_KEY"
  • do the same for Issuer and Audience
  • to see all local secrets execute
dotnet user-secrets list
  • more details can be found here
  1. Run RDLabAuthDemo.BasicJwt project:
  • try to get weather forecast, result must be 401.
  • in order to call this endpoint we need to get access token. Navigate to token endpoint with user name and password.
  • use this token to call weather forecast. You can add it to request header:
Bearer [PUT_YOUR_TOKEN_HERE]
  • or use Postman, select Authorization tab and pick Bearer Token in list. Paste your token to the field.

RDLabAuthDemo.IdentityServer

There are 2 examples: with Implicit Flow and Client Credentials. How to choose flow read here

  1. Client Credentials
  • run RDLabAuthDemo.IdentityServer and RDLabAuthDemo.IdentityServer.Api projects.
  • open Postman, create new request to weather forecast and execute, result must be 401.
  • select Authorization tab, select type OAuth 2.0
  • on right panel choose
    Grant Type: Client Credentials
    Access Token URL: https://localhost:5004/connect/token
    Client ID: rdlab.client
    Client Secret: 511536EF-F270-4058-80CA-1C89C192F69A
    Scope: rdLabApi
    
  • these values are taken from Config.cs file of RDLabAuthDemo.IdentityServer project
  • select Get New Access Token save it and try to execute request one more time
  1. Implicit Flow
  • make sure you are running RDLabAuthDemo.IdentityServer and RDLabAuthDemo.IdentityServer.MVC projects
  • try to navigate to Home page
  • Identity Server login page must be shown
  • enter bob as username and bob as password
  • give permissions to use your data
  1. To try Identity Server on your own, install identity server templates
dotnet new -i IdentityServer4.Templates
  • use this quickstart guide

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.