Advertisement
Guest User

Untitled

a guest
May 27th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Security.Claims;
  5. using System.Threading.Tasks;
  6. using IdentityServer4;
  7. using IdentityServer4.Models;
  8. using IdentityServer4.Test;
  9.  
  10. namespace IDSRVWASPNETIDENTITYTEST
  11. {
  12.     public class Config
  13.     {
  14.         // scopes define the resources in your system
  15.         public static IEnumerable<IdentityResource> GetIdentityResources()
  16.         {
  17.             return new List<IdentityResource>
  18.             {
  19.                 new IdentityResources.OpenId(),
  20.                 new IdentityResources.Profile(),
  21.             };
  22.         }
  23.  
  24.         public static IEnumerable<ApiResource> GetApiResources()
  25.         {
  26.             return new List<ApiResource>
  27.             {
  28.                 new ApiResource("api1", "My API")
  29.             };
  30.         }
  31.  
  32.         // clients want to access resources (aka scopes)
  33.         public static IEnumerable<Client> GetClients()
  34.         {
  35.             // client credentials client
  36.             return new List<Client>
  37.             {
  38.                 new Client
  39.                 {
  40.                     ClientId = "client",
  41.                     AllowedGrantTypes = GrantTypes.ClientCredentials,
  42.  
  43.                     ClientSecrets =
  44.                     {
  45.                         new Secret("secret".Sha256())
  46.                     },
  47.                     AllowedScopes = { "api1" }
  48.                 },
  49.  
  50.                 // resource owner password grant client
  51.                 new Client
  52.                 {
  53.                     ClientId = "ro.client",
  54.                     AllowedGrantTypes = GrantTypes.ResourceOwnerPassword,
  55.  
  56.                     ClientSecrets =
  57.                     {
  58.                         new Secret("secret".Sha256())
  59.                     },
  60.                     AllowedScopes = { "api1" }
  61.                 },
  62.  
  63.                 // OpenID Connect hybrid flow and client credentials client (MVC)
  64.                 new Client
  65.                 {
  66.                     ClientId = "mvc",
  67.                     ClientName = "MVC Client",
  68.                     AllowedGrantTypes = GrantTypes.HybridAndClientCredentials,
  69.  
  70.                     RequireConsent = false,
  71.  
  72.                     ClientSecrets =
  73.                     {
  74.                         new Secret("secret".Sha256())
  75.                     },
  76.  
  77.                     RedirectUris = { "http://localhost:5002/signin-oidc" },
  78.                     PostLogoutRedirectUris = { "http://localhost:5002/signout-callback-oidc" },
  79.  
  80.                     AllowedScopes =
  81.                     {
  82.                         IdentityServerConstants.StandardScopes.OpenId,
  83.                         IdentityServerConstants.StandardScopes.Profile,
  84.                         "api1"
  85.                     },
  86.                     AllowOfflineAccess = true
  87.                 }
  88.             };
  89.         }
  90.  
  91.         public static List<TestUser> GetUsers()
  92.         {
  93.             return new List<TestUser>
  94.             {
  95.                 new TestUser
  96.                 {
  97.                     SubjectId = "1",
  98.                     Username = "alice",
  99.                     Password = "password",
  100.  
  101.                     Claims = new List<Claim>
  102.                     {
  103.                         new Claim("name", "Alice"),
  104.                         new Claim("website", "https://alice.com")
  105.                     }
  106.                 },
  107.                 new TestUser
  108.                 {
  109.                     SubjectId = "2",
  110.                     Username = "bob",
  111.                     Password = "password",
  112.  
  113.                     Claims = new List<Claim>
  114.                     {
  115.                         new Claim("name", "Bob"),
  116.                         new Claim("website", "https://bob.com")
  117.                     }
  118.                 }
  119.             };
  120.         }
  121.     }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement