Browse Source

Add authorization code grant to the App client (the angular client).

pull/5048/head
Halil İbrahim Kalkan 6 years ago
parent
commit
483210edb2
  1. 3
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json
  2. 23
      templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

3
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.DbMigrator/appsettings.json

@ -11,7 +11,8 @@
}, },
"MyProjectName_App": { "MyProjectName_App": {
"ClientId": "MyProjectName_App", "ClientId": "MyProjectName_App",
"ClientSecret": "1q2w3e*" "ClientSecret": "1q2w3e*",
"RootUrl": "http://localhost:4200"
} }
} }
} }

23
templates/app/aspnet-core/src/MyCompanyName.MyProjectName.Domain/IdentityServer/IdentityServerDataSeedContributor.cs

@ -126,15 +126,20 @@ namespace MyCompanyName.MyProjectName.IdentityServer
); );
} }
//Console Test Client //Console Test / Angular Client
var consoleClientId = configurationSection["MyProjectName_App:ClientId"]; var consoleAndAngularClientId = configurationSection["MyProjectName_App:ClientId"];
if (!consoleClientId.IsNullOrWhiteSpace()) if (!consoleAndAngularClientId.IsNullOrWhiteSpace())
{ {
var webClientRootUrl = configurationSection["MyProjectName_App:RootUrl"]?.TrimEnd('/');
await CreateClientAsync( await CreateClientAsync(
name: consoleClientId, name: consoleAndAngularClientId,
scopes: commonScopes, scopes: commonScopes,
grantTypes: new[] {"password", "client_credentials"}, grantTypes: new[] {"password", "client_credentials", "authorization_code"},
secret: (configurationSection["MyProjectName_App:ClientSecret"] ?? "1q2w3e*").Sha256() secret: (configurationSection["MyProjectName_App:ClientSecret"] ?? "1q2w3e*").Sha256(),
requireClientSecret: false,
redirectUri: webClientRootUrl,
postLogoutRedirectUri: webClientRootUrl
); );
} }
} }
@ -147,6 +152,8 @@ namespace MyCompanyName.MyProjectName.IdentityServer
string redirectUri = null, string redirectUri = null,
string postLogoutRedirectUri = null, string postLogoutRedirectUri = null,
string frontChannelLogoutUri = null, string frontChannelLogoutUri = null,
bool requireClientSecret = true,
bool requirePkce = false,
IEnumerable<string> permissions = null) IEnumerable<string> permissions = null)
{ {
var client = await _clientRepository.FindByCliendIdAsync(name); var client = await _clientRepository.FindByCliendIdAsync(name);
@ -168,7 +175,9 @@ namespace MyCompanyName.MyProjectName.IdentityServer
AuthorizationCodeLifetime = 300, AuthorizationCodeLifetime = 300,
IdentityTokenLifetime = 300, IdentityTokenLifetime = 300,
RequireConsent = false, RequireConsent = false,
FrontChannelLogoutUri = frontChannelLogoutUri FrontChannelLogoutUri = frontChannelLogoutUri,
RequireClientSecret = requireClientSecret,
RequirePkce = requirePkce
}, },
autoSave: true autoSave: true
); );

Loading…
Cancel
Save