Giter Site home page Giter Site logo

identity-server-full's Introduction

Identity Server Demo

Startup

Create a new Empty ASPNET Core 3.1 Project.

  • Add Identity Server 4 nuget packet

  • Edit Startup.cs to add IdentityServer 4

  • Create Configuration/InMemoryConfig.cs

    InMemoryConfig.cs

         public static class InMemoryConfig
     {
         //RETURN IN MEMORY IDENTITY RESOURCES
         public static IEnumerable<IdentityResource> GetIdentityResources() =>
             new List<IdentityResource>()
             {
                 new IdentityResources.OpenId(),
                 new IdentityResources.Profile()
             };
    
         //RETURN IN MEMORY USERS
         public static List<TestUser> GetUsers() =>
             new List<TestUser>()
             {
                 new TestUser()
                 {
                     SubjectId = "fdsfsdfsd",
                     Username = "Andrea",
                     Password = "AndreaPassword",
                     Claims = new List<Claim>()
                     {
                         new Claim("given_name", "Andrea"),
                         new Claim("family_name", "Merlin")
                     }
                 },
                 new TestUser()
                 {
                     SubjectId = "ggjflgdlgdfljg",
                     Username = "Visual",
                     Password = "VisualPassword",
                     Claims = new List<Claim>()
                     {
                         new Claim("given_name", "Visual"),
                         new Claim("family_name", "Studio")
                     }
                 }
             };
    
         //RETURN IN MEMORY CLIENTS
         public static IEnumerable<Client> GetClients()
         {
             return new List<Client>()
             {
                 new Client()
                 {
                     ClientId = "company-employee",
                     ClientSecrets = new[] {new Secret("demopassword".Sha512())},
                     AllowedGrantTypes = GrantTypes.ResourceOwnerPasswordAndClientCredentials,   //flow types
                     AllowedScopes =  { IdentityServerConstants.StandardScopes.OpenId, "companyApi"}
                 }
             };
         }
    
         //RETURN API RESOURCES
         public static IEnumerable<ApiResource> GetApiResources() =>
             new List<ApiResource>() { new ApiResource("companyApi", "description") };
        
     }
    
    
    • Add Authenticaton with JWT Bearer via nuget: Microsoft.AspNetCore.Authentication.JwtBearer

    • Add Bearer configuration services.AddAuthentication("Bearer").AddJwtBearer("Bearer", opt => { opt.RequireHttpsMetadata = false; opt.Authority = "https://localhost:5005"; opt.Audience = "companyApi"; });

Integration

  • Install dotnet Core Identity Server Templates (from command line)
    dotnet new --install "IdentityServer4.Templates"
    
  • Add Identity UI Template (in the project root folder)
    dotnet new is4ui
    
  • Add WebApi Resources in InMemoryConfig.cs

Client Test (http post)

  • Run the program
  • Test authentication with PostMan

Client Image

  • Login with in memory client

Bearer Token Test (http get)

  • Test Bearer Token Auth

Client Image

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.