Browse Source

Added OpenIddict Mvc Guide

pull/13460/head
Galip Tolga Erdem 4 years ago
parent
commit
b875d63652
  1. 142
      docs/en/Migration-Guides/OpenIddict-Mvc.md

142
docs/en/Migration-Guides/OpenIddict-Mvc.md

@ -0,0 +1,142 @@
# OpenIddict MVC/Razor UI Migration Guide
## Web Project (Non-Tiered Solution)
- In **MyApplication.Web.csproj** replace **project references**:
```csharp
<PackageReference Include="Volo.Abp.AspNetCore.Authentication.JwtBearer" Version="6.0.0-rc.1" />
<PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="6.0.0-rc.1" />
```
with
```csharp
<PackageReference Include="Volo.Abp.Account.Web" Version="6.0.0-rc.1" />
```
- In **MyApplicationWebModule.cs** replace usings and **module dependencies**:
```csharp
using Volo.Abp.AspNetCore.Authentication.JwtBearer;
...
typeof(AbpAccountWebIdentityServerModule),
typeof(AbpAspNetCoreAuthenticationJwtBearerModule),
```
with
```csharp
typeof(AbpAccountWebModule),
```
- In **MyApplicationWebModule.cs** `ConfigureServices` method **remove authentication configuration**:
```csharp
ConfigureAuthentication(context, configuration);
```
- In **MyApplicationWebModule.cs** `OnApplicationInitialization` method **remove IdentityServer and JwtToken midwares**:
```csharp
app.UseJwtTokenMiddleware();
app.UseIdentityServer();
```
- Delete `ConfigureAuthentication(ServiceConfigurationContext context, IConfiguration configuration)` private method which is no longer needed.
## Web Project (Tiered Solution)
- In the **MyApplicationWebModule.cs** update the `AddAbpOpenIdConnect` configurations:
```csharp
.AddAbpOpenIdConnect("oidc", options =>
{
options.Authority = configuration["AuthServer:Authority"];
options.RequireHttpsMetadata = Convert.ToBoolean(configuration["AuthServer:RequireHttpsMetadata"]);
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.ClientId = configuration["AuthServer:ClientId"];
options.ClientSecret = configuration["AuthServer:ClientSecret"];
options.UsePkce = true; // Add this line
options.SaveTokens = true;
options.GetClaimsFromUserInfoEndpoint = true; // Add this line
options.SignOutScheme = "Cookies";
options.Scope.Add("roles"); // Replace "role" with "roles"
options.Scope.Add("email");
options.Scope.Add("phone");
options.Scope.Add("MyApplication");
});
```
Replace role scope to **roles** and add **UsePkce** and **SignoutScheme** options.
## IdentityServer
This project is renamed to **AuthServer** after v6.0.0-rc1. You can also refactor and rename your project to *AuthServer* for easier updates in the future.
- In **MyApplication.IdentityServer.csproj** replace **project references**:
```csharp
<PackageReference Include="Volo.Abp.Account.Web.IdentityServer" Version="6.0.0-rc.1" />
```
with
```csharp
<PackageReference Include="Volo.Abp.Account.Web.OpenIddict" Version="6.0.0-rc.1" />
```
- In **MyApplicationIdentityServerModule.cs** replace usings and **module dependencies**:
```csharp
typeof(AbpAccountWebIdentityServerModule),
```
with
```csharp
typeof(AbpAccountWebOpenIddictModule),
```
- In the **MyApplicationIdentityServerModule.cs** add `PreConfigureServices` like below with your application name as the audience:
```csharp
public override void PreConfigureServices(ServiceConfigurationContext context)
{
PreConfigure<OpenIddictBuilder>(builder =>
{
builder.AddValidation(options =>
{
options.AddAudiences("MyApplication"); // Replace with your application name
options.UseLocalServer();
options.UseAspNetCore();
});
});
}
```
- In **MyApplicationIdentityServerModule.cs** `OnApplicationInitialization` method **remove IdentityServer midware**:
```csharp
app.UseIdentityServer();
```
## Http.Api.Host
- In the **MyApplicationHttpApiHostModule.cs** `OnApplicationInitialization` method, delete `c.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);` in `app.UseAbpSwaggerUI` options configurations which is no longer needed.
- In `appsettings.json` delete **SwaggerClientSecret** from the *AuthServer* section like below:
```json
"AuthServer": {
"Authority": "https://localhost:44345",
"RequireHttpsMetadata": "false",
"SwaggerClientId": "MyApplication_Swagger"
},
## See Also
* [OpenIddict Step-by-Step Guide](./OpenIddict-Step-by-Step.md)
Loading…
Cancel
Save