Skip to content

Commit ff782d2

Browse files
committed
Updating namespaces
1 parent 3ab4191 commit ff782d2

55 files changed

Lines changed: 1244 additions & 1330 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

content/StsServerIdentity/Config.cs

Lines changed: 78 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -5,94 +5,93 @@
55
using Microsoft.Extensions.Configuration;
66
using System.Collections.Generic;
77

8-
namespace StsServerIdentity
8+
namespace StsServerIdentity;
9+
10+
public class Config
911
{
10-
public class Config
12+
public static IEnumerable<IdentityResource> GetIdentityResources()
1113
{
12-
public static IEnumerable<IdentityResource> GetIdentityResources()
14+
return new List<IdentityResource>
1315
{
14-
return new List<IdentityResource>
15-
{
16-
new IdentityResources.OpenId(),
17-
new IdentityResources.Profile(),
18-
new IdentityResources.Email()
19-
};
20-
}
16+
new IdentityResources.OpenId(),
17+
new IdentityResources.Profile(),
18+
new IdentityResources.Email()
19+
};
20+
}
2121

22-
public static IEnumerable<ApiScope> GetApiScopes()
22+
public static IEnumerable<ApiScope> GetApiScopes()
23+
{
24+
return new List<ApiScope>
2325
{
24-
return new List<ApiScope>
25-
{
26-
//new ApiScope("dataEventRecords", "Scope for the dataEventRecords ApiResource"),
27-
//new ApiScope("securedFiles", "Scope for the securedFiles ApiResource")
28-
};
29-
}
26+
//new ApiScope("dataEventRecords", "Scope for the dataEventRecords ApiResource"),
27+
//new ApiScope("securedFiles", "Scope for the securedFiles ApiResource")
28+
};
29+
}
3030

31-
public static IEnumerable<ApiResource> GetApiResources()
31+
public static IEnumerable<ApiResource> GetApiResources()
32+
{
33+
return new List<ApiResource>
3234
{
33-
return new List<ApiResource>
34-
{
35-
//new ApiResource("dataEventRecordsApi")
36-
//{
37-
// ApiSecrets =
38-
// {
39-
// new Secret("dataEventRecordsSecret".Sha256())
40-
// },
41-
// Scopes = new List<string> { "dataEventRecords" }
42-
//},
43-
//new ApiResource("securedFilesApi")
44-
//{
45-
// ApiSecrets =
46-
// {
47-
// new Secret("securedFilesSecret".Sha256())
48-
// },
49-
// Scopes = new List<string> { "securedFiles" }
50-
//}
51-
};
52-
}
35+
//new ApiResource("dataEventRecordsApi")
36+
//{
37+
// ApiSecrets =
38+
// {
39+
// new Secret("dataEventRecordsSecret".Sha256())
40+
// },
41+
// Scopes = new List<string> { "dataEventRecords" }
42+
//},
43+
//new ApiResource("securedFilesApi")
44+
//{
45+
// ApiSecrets =
46+
// {
47+
// new Secret("securedFilesSecret".Sha256())
48+
// },
49+
// Scopes = new List<string> { "securedFiles" }
50+
//}
51+
};
52+
}
5353

54-
public static IEnumerable<Client> GetClients(IConfigurationSection stsConfig)
55-
{
56-
// TODO use configs in app
57-
//var yourConfig = stsConfig["ClientUrl"];
54+
public static IEnumerable<Client> GetClients(IConfigurationSection stsConfig)
55+
{
56+
// TODO use configs in app
57+
//var yourConfig = stsConfig["ClientUrl"];
5858

59-
return new List<Client>
60-
{
61-
// example code
62-
//new Client
63-
//{
64-
// ClientName = "angularclient",
65-
// ClientId = "angularclient",
66-
// AccessTokenType = AccessTokenType.Reference,
67-
// AccessTokenLifetime = 330,// 330 seconds, default 60 minutes
68-
// IdentityTokenLifetime = 30,
69-
// AllowedGrantTypes = GrantTypes.Implicit,
70-
// AllowAccessTokensViaBrowser = true,
71-
// RedirectUris = new List<string>
72-
// {
73-
// "https://localhost:44311",
74-
// "https://localhost:44311/silent-renew.html"
59+
return new List<Client>
60+
{
61+
// example code
62+
//new Client
63+
//{
64+
// ClientName = "angularclient",
65+
// ClientId = "angularclient",
66+
// AccessTokenType = AccessTokenType.Reference,
67+
// AccessTokenLifetime = 330,// 330 seconds, default 60 minutes
68+
// IdentityTokenLifetime = 30,
69+
// AllowedGrantTypes = GrantTypes.Implicit,
70+
// AllowAccessTokensViaBrowser = true,
71+
// RedirectUris = new List<string>
72+
// {
73+
// "https://localhost:44311",
74+
// "https://localhost:44311/silent-renew.html"
7575

76-
// },
77-
// PostLogoutRedirectUris = new List<string>
78-
// {
79-
// "https://localhost:44311/unauthorized",
80-
// "https://localhost:44311"
81-
// },
82-
// AllowedCorsOrigins = new List<string>
83-
// {
84-
// "https://localhost:44311",
85-
// "http://localhost:44311"
86-
// },
87-
// AllowedScopes = new List<string>
88-
// {
89-
// "openid",
90-
// "role",
91-
// "profile",
92-
// "email"
93-
// }
94-
//}
95-
};
96-
}
76+
// },
77+
// PostLogoutRedirectUris = new List<string>
78+
// {
79+
// "https://localhost:44311/unauthorized",
80+
// "https://localhost:44311"
81+
// },
82+
// AllowedCorsOrigins = new List<string>
83+
// {
84+
// "https://localhost:44311",
85+
// "http://localhost:44311"
86+
// },
87+
// AllowedScopes = new List<string>
88+
// {
89+
// "openid",
90+
// "role",
91+
// "profile",
92+
// "email"
93+
// }
94+
//}
95+
};
9796
}
9897
}

content/StsServerIdentity/Extensions.cs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,25 @@
33
using Microsoft.AspNetCore.Mvc;
44
using StsServerIdentity.Models.AccountViewModels;
55

6-
namespace StsServerIdentity
6+
namespace StsServerIdentity;
7+
8+
public static class Extensions
79
{
8-
public static class Extensions
10+
/// <summary>
11+
/// Checks if the redirect URI is for a native client.
12+
/// </summary>
13+
/// <returns></returns>
14+
public static bool IsNativeClient(this AuthorizationRequest context)
915
{
10-
/// <summary>
11-
/// Checks if the redirect URI is for a native client.
12-
/// </summary>
13-
/// <returns></returns>
14-
public static bool IsNativeClient(this AuthorizationRequest context)
15-
{
16-
return !context.RedirectUri.StartsWith("https", StringComparison.Ordinal)
17-
&& !context.RedirectUri.StartsWith("http", StringComparison.Ordinal);
18-
}
16+
return !context.RedirectUri.StartsWith("https", StringComparison.Ordinal)
17+
&& !context.RedirectUri.StartsWith("http", StringComparison.Ordinal);
18+
}
1919

20-
public static IActionResult LoadingPage(this Controller controller, string viewName, string redirectUri)
21-
{
22-
controller.HttpContext.Response.StatusCode = 200;
23-
controller.HttpContext.Response.Headers["Location"] = "";
20+
public static IActionResult LoadingPage(this Controller controller, string viewName, string redirectUri)
21+
{
22+
controller.HttpContext.Response.StatusCode = 200;
23+
controller.HttpContext.Response.Headers["Location"] = "";
2424

25-
return controller.View(viewName, new RedirectViewModel { RedirectUrl = redirectUri });
26-
}
25+
return controller.View(viewName, new RedirectViewModel { RedirectUrl = redirectUri });
2726
}
28-
}
27+
}

content/StsServerIdentity/IdentityWithAdditionalClaimsProfileService.cs

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,59 +10,58 @@
1010
using Microsoft.AspNetCore.Identity;
1111
using IdentityServer4;
1212

13-
namespace StsServerIdentity
14-
{
15-
public class IdentityWithAdditionalClaimsProfileService : IProfileService
16-
{
17-
private readonly IUserClaimsPrincipalFactory<ApplicationUser> _claimsFactory;
18-
private readonly UserManager<ApplicationUser> _userManager;
19-
20-
public IdentityWithAdditionalClaimsProfileService(UserManager<ApplicationUser> userManager, IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory)
21-
{
22-
_userManager = userManager;
23-
_claimsFactory = claimsFactory;
24-
}
13+
namespace StsServerIdentity;
2514

26-
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
27-
{
28-
var sub = context.Subject.GetSubjectId();
29-
30-
var user = await _userManager.FindByIdAsync(sub);
31-
var principal = await _claimsFactory.CreateAsync(user);
15+
public class IdentityWithAdditionalClaimsProfileService : IProfileService
16+
{
17+
private readonly IUserClaimsPrincipalFactory<ApplicationUser> _claimsFactory;
18+
private readonly UserManager<ApplicationUser> _userManager;
3219

33-
var claims = principal.Claims.ToList();
20+
public IdentityWithAdditionalClaimsProfileService(UserManager<ApplicationUser> userManager, IUserClaimsPrincipalFactory<ApplicationUser> claimsFactory)
21+
{
22+
_userManager = userManager;
23+
_claimsFactory = claimsFactory;
24+
}
3425

35-
claims = claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();
36-
claims.Add(new Claim(JwtClaimTypes.GivenName, user.UserName));
26+
public async Task GetProfileDataAsync(ProfileDataRequestContext context)
27+
{
28+
var sub = context.Subject.GetSubjectId();
3729

38-
if (user.IsAdmin)
39-
{
40-
claims.Add(new Claim(JwtClaimTypes.Role, "admin"));
41-
}
42-
else
43-
{
44-
claims.Add(new Claim(JwtClaimTypes.Role, "user"));
45-
}
30+
var user = await _userManager.FindByIdAsync(sub);
31+
var principal = await _claimsFactory.CreateAsync(user);
4632

47-
if (user.TwoFactorEnabled)
48-
{
49-
claims.Add(new Claim("amr", "mfa"));
50-
}
51-
else
52-
{
53-
claims.Add(new Claim("amr", "pwd")); ;
54-
}
33+
var claims = principal.Claims.ToList();
5534

56-
claims.Add(new Claim(IdentityServerConstants.StandardScopes.Email, user.Email));
35+
claims = claims.Where(claim => context.RequestedClaimTypes.Contains(claim.Type)).ToList();
36+
claims.Add(new Claim(JwtClaimTypes.GivenName, user.UserName));
5737

58-
context.IssuedClaims = claims;
38+
if (user.IsAdmin)
39+
{
40+
claims.Add(new Claim(JwtClaimTypes.Role, "admin"));
41+
}
42+
else
43+
{
44+
claims.Add(new Claim(JwtClaimTypes.Role, "user"));
5945
}
6046

61-
public async Task IsActiveAsync(IsActiveContext context)
47+
if (user.TwoFactorEnabled)
48+
{
49+
claims.Add(new Claim("amr", "mfa"));
50+
}
51+
else
6252
{
63-
var sub = context.Subject.GetSubjectId();
64-
var user = await _userManager.FindByIdAsync(sub);
65-
context.IsActive = user != null;
53+
claims.Add(new Claim("amr", "pwd")); ;
6654
}
55+
56+
claims.Add(new Claim(IdentityServerConstants.StandardScopes.Email, user.Email));
57+
58+
context.IssuedClaims = claims;
59+
}
60+
61+
public async Task IsActiveAsync(IsActiveContext context)
62+
{
63+
var sub = context.Subject.GetSubjectId();
64+
var user = await _userManager.FindByIdAsync(sub);
65+
context.IsActive = user != null;
6766
}
6867
}

0 commit comments

Comments
 (0)