Add project files.

This commit is contained in:
2023-04-29 09:17:17 +03:00
commit 62178f1f32
493 changed files with 45863 additions and 0 deletions
@@ -0,0 +1,34 @@
namespace MyOffice.Web.Identity.Configure;
using MyOffice.Web.Infrastructure;
using IdentityServer4.AccessTokenValidation;
using Microsoft.Extensions.Options;
public class ConfigureIdentityServerOptions : IConfigureNamedOptions<IdentityServerAuthenticationOptions>
{
readonly GlobalSettings _globalSettings;
readonly ILogger<ConfigureIdentityServerOptions> _logger;
public ConfigureIdentityServerOptions(
GlobalSettings globalSettings,
ILogger<ConfigureIdentityServerOptions> logger
)
{
_globalSettings = globalSettings;
_logger = logger;
}
public void Configure(string? name, IdentityServerAuthenticationOptions options)
{
//_logger.LogError($"Configure: {_globalSettings.Host}");
if (name == IdentityServerAuthenticationDefaults.AuthenticationScheme)
{
options.RequireHttpsMetadata = false;
options.ApiName = IdentityServerConfig.ApiName;
options.Authority = _globalSettings.Host;
}
}
// This won't be called, but is required for the IConfigureNamedOptions interface
public void Configure(IdentityServerAuthenticationOptions options) => Configure(Options.DefaultName, options);
}
@@ -0,0 +1,107 @@
namespace MyOffice.Web.Identity.Configure;
using IdentityModel;
using IdentityServer4;
using IdentityServer4.Models;
public class IdentityServerConfig
{
public static class ClaimConstants
{
public const string Subject = "subject";
public const string Permission = "permission";
}
public static class ScopeConstants
{
public const string Roles = "roles";
}
public const string ApiName = "api";
public const string ApiFriendlyName = "MyOffice.Web API";
public const string AppClientID = "angulartemplate_spa";
public static IEnumerable<IdentityResource> GetIdentityResources()
{
return new List<IdentityResource>
{
new IdentityResources.OpenId(),
new IdentityResources.Profile(),
new IdentityResources.Phone(),
new IdentityResources.Email(),
new(ScopeConstants.Roles, new List<string> { JwtClaimTypes.Role })
};
}
public static IEnumerable<ApiScope> GetApiScopes()
{
return new List<ApiScope>
{
new(ApiName, ApiFriendlyName)
{
UserClaims =
{
JwtClaimTypes.Name,
JwtClaimTypes.Email,
JwtClaimTypes.PhoneNumber,
JwtClaimTypes.Role,
ClaimConstants.Permission
}
}
};
}
public static IEnumerable<ApiResource> GetApiResources()
{
return new List<ApiResource>
{
new(ApiName)
{
Scopes = { ApiName }
}
};
}
public static IEnumerable<Client> GetClients()
{
return new List<Client>
{
new()
{
ClientId = AppClientID,
ClientSecrets = new List<Secret>
{
new Secret("secret".Sha256())
},
AllowedGrantTypes = new[]
{
GrantType.AuthorizationCode,
GrantType.ClientCredentials,
GrantType.DeviceFlow,
GrantType.ResourceOwnerPassword,
"external"
},
AllowAccessTokensViaBrowser = true,
RequireClientSecret = false,
RedirectUris = new[]
{
"http://localhost:4200/silent-refresh.html",
},
AllowedScopes =
{
IdentityServerConstants.StandardScopes.OpenId,
IdentityServerConstants.StandardScopes.Profile,
IdentityServerConstants.StandardScopes.Phone,
IdentityServerConstants.StandardScopes.Email,
ScopeConstants.Roles,
ApiName
},
AllowOfflineAccess = true,
RefreshTokenExpiration = TokenExpiration.Sliding,
RefreshTokenUsage = TokenUsage.OneTimeOnly
}
};
}
}