-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4a89f4d
commit fc4c439
Showing
2 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/OrchardCore.Modules/OrchardCore.OpenId/Migrations/DefaultScopesMigration.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using Microsoft.Extensions.Localization; | ||
using OpenIddict.Abstractions; | ||
using OrchardCore.Data.Migration; | ||
using OrchardCore.Environment.Shell.Scope; | ||
using OrchardCore.OpenId.Abstractions.Descriptors; | ||
using OrchardCore.OpenId.Abstractions.Managers; | ||
|
||
namespace OrchardCore.OpenId.Migrations; | ||
|
||
public sealed class DefaultScopesMigration : DataMigration | ||
{ | ||
#pragma warning disable CA1822 // Mark members as static | ||
public int Create() | ||
#pragma warning restore CA1822 // Mark members as static | ||
{ | ||
ShellScope.AddDeferredTask(async shellScope => | ||
{ | ||
var S = shellScope.ServiceProvider.GetService<IStringLocalizer<DefaultScopesMigration>>(); | ||
var scopeManager = shellScope.ServiceProvider.GetRequiredService<IOpenIdScopeManager>(); | ||
if (await scopeManager.FindByNameAsync(OpenIddictConstants.Scopes.Profile) == null) | ||
{ | ||
var descriptor = new OpenIdScopeDescriptor | ||
{ | ||
DisplayName = S["Profile"], | ||
Name = OpenIddictConstants.Scopes.Profile, | ||
Description = S["Requests access to the user's default profile information."] | ||
}; | ||
await scopeManager.CreateAsync(descriptor); | ||
} | ||
if (await scopeManager.FindByNameAsync(OpenIddictConstants.Scopes.Email) == null) | ||
{ | ||
var descriptor = new OpenIdScopeDescriptor | ||
{ | ||
DisplayName = S["Email"], | ||
Name = OpenIddictConstants.Scopes.Email, | ||
Description = S["Requests access to the user's email address. This scope provides the email and email_verified claims, which indicate the user's email address and whether it has been verified."] | ||
}; | ||
await scopeManager.CreateAsync(descriptor); | ||
} | ||
if (await scopeManager.FindByNameAsync(OpenIddictConstants.Scopes.Phone) == null) | ||
{ | ||
var descriptor = new OpenIdScopeDescriptor | ||
{ | ||
DisplayName = S["Phone"], | ||
Name = OpenIddictConstants.Scopes.Phone, | ||
Description = S["Requests access to the user's phone number. This scope includes the phone_number and phone_number_verified claims, which provide the user's phone number and indicate whether it has been verified."] | ||
}; | ||
await scopeManager.CreateAsync(descriptor); | ||
} | ||
}); | ||
|
||
return 1; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters