Giter Club home page Giter Club logo

identityserver4_dotnetcore's Introduction

IdentityServer4_DotNetCore

Secure public microservice with the help of Identiry server 4 using jwt bearer token by craete .net core 3.1

Step 1: Create .Net Core Web App named "IdentityServer"

Step 2: Add nuget packages as: => IdentityServer4 3.1.2 => IdentityServer4.EntityFramework 3.1.2

Step 3: Add Config.css class in proj => Create GetApiResource method => then create GetClient method note: you set 4 values care fully
=> client_id = "secret_client_id" => grant_type = "client_credentials" => scope = "apiscope" => client_secret = "secret"

step 4: add service in Configure method of Startup class with services.AddIdentityServer(). AddDeveloperSigningCredential() .AddOperationalStore(option => { option.EnableTokenCleanup = true; option.TokenCleanupInterval = 30; // in seconds }) .AddInMemoryApiResources(Config.GetApiRescources()) .AddInMemoryClients(Config.GetClients()); step 5: Add medleware in ConfigureService Method app.UseIdentityServer();

step 6: Create second prject with .net core api api

step 7: install nuget pkg => jwtbearer package 3.1.1

step 8: add services

    services.AddAuthentication(options =>
        {
            options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
        }).AddJwtBearer(o =>
        {
            o.Authority = "https://localhost:44311";
            o.Audience = "myresourceapi";
            o.RequireHttpsMetadata = false;
        });

        services.AddAuthorization(options =>
        {
            options.AddPolicy("PublicSecure", pollicy => PolicyHandler.AuthorizeRequest(pollicy));
        });

step 9: add meddleware

	app.UseAuthentication();
        app.UseAuthorization();

step 9: add authorize filter with policy descibe in service as => [Authorize(Policy = "PublicSecure")]

run both project and get jwt token from identiry server then by passing token in request try to get data from microserive

identityserver4_dotnetcore's People

Contributors

alihaider981 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.