mirror of https://github.com/abpframework/abp.git
17 changed files with 2411 additions and 6 deletions
@ -0,0 +1,151 @@ |
|||
using System; |
|||
using System.Globalization; |
|||
using System.Threading.Tasks; |
|||
using OpenIddict.Abstractions; |
|||
using Volo.Abp.Data; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.MultiTenancy; |
|||
|
|||
namespace MyCompanyName.MyProjectName.OpenIddict; |
|||
|
|||
public class OpenIddictDataSeedContributor : IDataSeedContributor, ITransientDependency |
|||
{ |
|||
private readonly ICurrentTenant _currentTenant; |
|||
private readonly IOpenIddictApplicationManager _applicationManager; |
|||
private readonly IOpenIddictScopeManager _scopeManager; |
|||
|
|||
public OpenIddictDataSeedContributor( |
|||
ICurrentTenant currentTenant, |
|||
IOpenIddictApplicationManager applicationManager, |
|||
IOpenIddictScopeManager scopeManager) |
|||
{ |
|||
_currentTenant = currentTenant; |
|||
_applicationManager = applicationManager; |
|||
_scopeManager = scopeManager; |
|||
} |
|||
|
|||
public async Task SeedAsync(DataSeedContext context) |
|||
{ |
|||
if (await _scopeManager.FindByNameAsync("AbpAPI") == null) |
|||
{ |
|||
await _scopeManager.CreateAsync(new OpenIddictScopeDescriptor() |
|||
{ |
|||
Name = "AbpAPI", |
|||
DisplayName = "Abp API access", |
|||
DisplayNames = |
|||
{ |
|||
[CultureInfo.GetCultureInfo("zh-Hans")] = "演示 API 访问", |
|||
[CultureInfo.GetCultureInfo("tr")] = "API erişimi" |
|||
}, |
|||
Resources = |
|||
{ |
|||
"AbpAPIResource" |
|||
} |
|||
}); |
|||
} |
|||
|
|||
if (await _applicationManager.FindByClientIdAsync("AbpApp") == null) |
|||
{ |
|||
await _applicationManager.CreateAsync(new OpenIddictApplicationDescriptor |
|||
{ |
|||
ClientId = "AbpApp", |
|||
ClientSecret = "1q2w3e*", |
|||
ConsentType = OpenIddictConstants.ConsentTypes.Explicit, |
|||
DisplayName = "Abp Application", |
|||
PostLogoutRedirectUris = |
|||
{ |
|||
new Uri("https://localhost:44302/signout-callback-oidc"), |
|||
new Uri("http://localhost:4200") |
|||
}, |
|||
RedirectUris = |
|||
{ |
|||
new Uri("https://localhost:44302/signin-oidc"), |
|||
new Uri("http://localhost:4200") |
|||
}, |
|||
Permissions = |
|||
{ |
|||
OpenIddictConstants.Permissions.Endpoints.Authorization, |
|||
OpenIddictConstants.Permissions.Endpoints.Token, |
|||
OpenIddictConstants.Permissions.Endpoints.Device, |
|||
OpenIddictConstants.Permissions.Endpoints.Introspection, |
|||
OpenIddictConstants.Permissions.Endpoints.Revocation, |
|||
OpenIddictConstants.Permissions.Endpoints.Logout, |
|||
|
|||
OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode, |
|||
OpenIddictConstants.Permissions.GrantTypes.Implicit, |
|||
OpenIddictConstants.Permissions.GrantTypes.Password, |
|||
OpenIddictConstants.Permissions.GrantTypes.RefreshToken, |
|||
OpenIddictConstants.Permissions.GrantTypes.DeviceCode, |
|||
OpenIddictConstants.Permissions.GrantTypes.ClientCredentials, |
|||
|
|||
OpenIddictConstants.Permissions.ResponseTypes.Code, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeIdToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeIdTokenToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.IdToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.IdTokenToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.None, |
|||
OpenIddictConstants.Permissions.ResponseTypes.Token, |
|||
|
|||
OpenIddictConstants.Permissions.Scopes.Roles, |
|||
OpenIddictConstants.Permissions.Scopes.Profile, |
|||
OpenIddictConstants.Permissions.Scopes.Email, |
|||
OpenIddictConstants.Permissions.Scopes.Address, |
|||
OpenIddictConstants.Permissions.Scopes.Phone, |
|||
OpenIddictConstants.Permissions.Prefixes.Scope + "AbpAPI" |
|||
} |
|||
}); |
|||
} |
|||
|
|||
if (await _applicationManager.FindByClientIdAsync("AbpBlazorWASMApp") == null) |
|||
{ |
|||
await _applicationManager.CreateAsync(new OpenIddictApplicationDescriptor |
|||
{ |
|||
ClientId = "AbpBlazorWASMApp", |
|||
ConsentType = OpenIddictConstants.ConsentTypes.Explicit, |
|||
DisplayName = "Abp Blazor WASM Application", |
|||
PostLogoutRedirectUris = |
|||
{ |
|||
new Uri("https://localhost:44304/authentication/logout-callback") |
|||
}, |
|||
RedirectUris = |
|||
{ |
|||
new Uri("https://localhost:44304/authentication/login-callback") |
|||
}, |
|||
Permissions = |
|||
{ |
|||
OpenIddictConstants.Permissions.Endpoints.Authorization, |
|||
OpenIddictConstants.Permissions.Endpoints.Token, |
|||
OpenIddictConstants.Permissions.Endpoints.Device, |
|||
OpenIddictConstants.Permissions.Endpoints.Introspection, |
|||
OpenIddictConstants.Permissions.Endpoints.Revocation, |
|||
OpenIddictConstants.Permissions.Endpoints.Logout, |
|||
|
|||
OpenIddictConstants.Permissions.GrantTypes.AuthorizationCode, |
|||
OpenIddictConstants.Permissions.GrantTypes.Implicit, |
|||
OpenIddictConstants.Permissions.GrantTypes.Password, |
|||
OpenIddictConstants.Permissions.GrantTypes.RefreshToken, |
|||
OpenIddictConstants.Permissions.GrantTypes.DeviceCode, |
|||
OpenIddictConstants.Permissions.GrantTypes.ClientCredentials, |
|||
|
|||
OpenIddictConstants.Permissions.ResponseTypes.Code, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeIdToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeIdTokenToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.CodeToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.IdToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.IdTokenToken, |
|||
OpenIddictConstants.Permissions.ResponseTypes.None, |
|||
OpenIddictConstants.Permissions.ResponseTypes.Token, |
|||
|
|||
OpenIddictConstants.Permissions.Scopes.Roles, |
|||
OpenIddictConstants.Permissions.Scopes.Profile, |
|||
OpenIddictConstants.Permissions.Scopes.Email, |
|||
OpenIddictConstants.Permissions.Scopes.Address, |
|||
OpenIddictConstants.Permissions.Scopes.Phone, |
|||
|
|||
OpenIddictConstants.Permissions.Prefixes.Scope + "AbpAPI" |
|||
} |
|||
}); |
|||
} |
|||
} |
|||
} |
|||
File diff suppressed because it is too large
@ -0,0 +1,189 @@ |
|||
using System; |
|||
using Microsoft.EntityFrameworkCore.Migrations; |
|||
|
|||
#nullable disable |
|||
|
|||
namespace MyCompanyName.MyProjectName.Migrations |
|||
{ |
|||
public partial class Installed_OpenIddict_Module : Migration |
|||
{ |
|||
protected override void Up(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.CreateTable( |
|||
name: "OpenIddictApplications", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ClientId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true), |
|||
ClientSecret = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConsentType = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Permissions = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
PostLogoutRedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
RedirectUris = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Requirements = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_OpenIddictApplications", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "OpenIddictScopes", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
Description = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Descriptions = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
DisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
DisplayNames = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Name = table.Column<string>(type: "nvarchar(200)", maxLength: 200, nullable: true), |
|||
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Resources = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_OpenIddictScopes", x => x.Id); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "OpenIddictAuthorizations", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ApplicationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Scopes = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
Subject = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true), |
|||
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_OpenIddictAuthorizations", x => x.Id); |
|||
table.ForeignKey( |
|||
name: "FK_OpenIddictAuthorizations_OpenIddictApplications_ApplicationId", |
|||
column: x => x.ApplicationId, |
|||
principalTable: "OpenIddictApplications", |
|||
principalColumn: "Id"); |
|||
}); |
|||
|
|||
migrationBuilder.CreateTable( |
|||
name: "OpenIddictTokens", |
|||
columns: table => new |
|||
{ |
|||
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false), |
|||
ApplicationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
AuthorizationId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
CreationDate = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
ExpirationDate = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
Payload = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
Properties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
RedemptionDate = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
ReferenceId = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: true), |
|||
Status = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
Subject = table.Column<string>(type: "nvarchar(400)", maxLength: 400, nullable: true), |
|||
Type = table.Column<string>(type: "nvarchar(50)", maxLength: 50, nullable: true), |
|||
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true), |
|||
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true), |
|||
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false), |
|||
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true), |
|||
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false), |
|||
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true), |
|||
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true) |
|||
}, |
|||
constraints: table => |
|||
{ |
|||
table.PrimaryKey("PK_OpenIddictTokens", x => x.Id); |
|||
table.ForeignKey( |
|||
name: "FK_OpenIddictTokens_OpenIddictApplications_ApplicationId", |
|||
column: x => x.ApplicationId, |
|||
principalTable: "OpenIddictApplications", |
|||
principalColumn: "Id"); |
|||
table.ForeignKey( |
|||
name: "FK_OpenIddictTokens_OpenIddictAuthorizations_AuthorizationId", |
|||
column: x => x.AuthorizationId, |
|||
principalTable: "OpenIddictAuthorizations", |
|||
principalColumn: "Id"); |
|||
}); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictApplications_ClientId", |
|||
table: "OpenIddictApplications", |
|||
column: "ClientId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictAuthorizations_ApplicationId_Status_Subject_Type", |
|||
table: "OpenIddictAuthorizations", |
|||
columns: new[] { "ApplicationId", "Status", "Subject", "Type" }); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictScopes_Name", |
|||
table: "OpenIddictScopes", |
|||
column: "Name"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictTokens_ApplicationId_Status_Subject_Type", |
|||
table: "OpenIddictTokens", |
|||
columns: new[] { "ApplicationId", "Status", "Subject", "Type" }); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictTokens_AuthorizationId", |
|||
table: "OpenIddictTokens", |
|||
column: "AuthorizationId"); |
|||
|
|||
migrationBuilder.CreateIndex( |
|||
name: "IX_OpenIddictTokens_ReferenceId", |
|||
table: "OpenIddictTokens", |
|||
column: "ReferenceId"); |
|||
} |
|||
|
|||
protected override void Down(MigrationBuilder migrationBuilder) |
|||
{ |
|||
migrationBuilder.DropTable( |
|||
name: "OpenIddictScopes"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "OpenIddictTokens"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "OpenIddictAuthorizations"); |
|||
|
|||
migrationBuilder.DropTable( |
|||
name: "OpenIddictApplications"); |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue