Browse Source

Created AbpAspNetCoreAuthenticationOAuthModule module.

pull/217/head
Halil İbrahim Kalkan 9 years ago
parent
commit
6b81785224
  1. 7
      Volo.Abp.sln
  2. 1
      src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj
  3. 16
      src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs
  4. 17
      src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs
  5. 25
      src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo.Abp.AspNetCore.Authentication.OAuth.csproj
  6. 15
      src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/AbpAspNetCoreAuthenticationOAuthModule.cs
  7. 20
      src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs

7
Volo.Abp.sln

@ -302,6 +302,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Volo.Abp.Account.Web.Identi
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MicroserviceDemo.ConsoleClient", "src\MicroserviceDemo\MicroserviceDemo.ConsoleClient\MicroserviceDemo.ConsoleClient.csproj", "{CD4E755D-D47C-45B1-AFB3-3444FF2E2E39}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Volo.Abp.AspNetCore.Authentication.OAuth", "src\Volo.Abp.AspNetCore.Authentication.OAuth\Volo.Abp.AspNetCore.Authentication.OAuth.csproj", "{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -796,6 +798,10 @@ Global
{CD4E755D-D47C-45B1-AFB3-3444FF2E2E39}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CD4E755D-D47C-45B1-AFB3-3444FF2E2E39}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CD4E755D-D47C-45B1-AFB3-3444FF2E2E39}.Release|Any CPU.Build.0 = Release|Any CPU
{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@ -943,6 +949,7 @@ Global
{A177B8B7-ACAD-4F75-B6D4-B72F7BC2E40A} = {3510E248-DC9F-4A07-8134-02E7F5CC5783}
{E4AB8A4F-BB59-4BDB-B915-877CE97D8113} = {DB012309-74FD-4D5A-B843-DD77BF053BF4}
{CD4E755D-D47C-45B1-AFB3-3444FF2E2E39} = {3510E248-DC9F-4A07-8134-02E7F5CC5783}
{A1C792B7-0DBF-460D-9158-A1A68A2D9C1A} = {C4C6961D-01CC-49A5-8B96-2A36E71CF01F}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {BB97ECF4-9A84-433F-A80B-2A3285BDD1D5}

1
src/MicroserviceDemo/MicroserviceDemo.Web/MicroserviceDemo.Web.csproj

@ -25,6 +25,7 @@
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Volo.Abp.AspNetCore.Authentication.OAuth\Volo.Abp.AspNetCore.Authentication.OAuth.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Identity.EntityFrameworkCore\Volo.Abp.Identity.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\..\Volo.Abp.Identity.HttpApi\Volo.Abp.Identity.HttpApi.csproj" />

16
src/MicroserviceDemo/MicroserviceDemo.Web/MicroservicesDemoWebModule.cs

@ -1,5 +1,5 @@
using System;
using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.OAuth.Claims;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity;
@ -9,6 +9,7 @@ using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
using Swashbuckle.AspNetCore.Swagger;
using Volo.Abp;
using Volo.Abp.AspNetCore.Authentication.OAuth;
using Volo.Abp.AspNetCore.Modularity;
using Volo.Abp.AspNetCore.Mvc.Bundling;
using Volo.Abp.Autofac;
@ -22,7 +23,6 @@ using Volo.Abp.Modularity;
using Volo.Abp.MultiTenancy;
using Volo.Abp.MultiTenancy.Web;
using Volo.Abp.Permissions.EntityFrameworkCore;
using Volo.Abp.Security.Claims;
namespace MicroserviceDemo.Web
{
@ -33,6 +33,7 @@ namespace MicroserviceDemo.Web
[DependsOn(typeof(AbpIdentityEntityFrameworkCoreModule))]
[DependsOn(typeof(AbpMultiTenancyHttpApiClientModule))]
[DependsOn(typeof(AbpMultiTenancyWebModule))]
[DependsOn(typeof(AbpAspNetCoreAuthenticationOAuthModule))]
public class MicroservicesDemoWebModule : AbpModule
{
public override void PreConfigureServices(IServiceCollection services)
@ -89,6 +90,7 @@ namespace MicroserviceDemo.Web
options.ClientId = "client";
options.ClientSecret = "secret";
options.ResponseType = OpenIdConnectResponseType.CodeIdToken;
options.SaveTokens = true;
@ -99,15 +101,7 @@ namespace MicroserviceDemo.Web
options.Scope.Add("phone");
options.Scope.Add("multi-tenancy-api");
options.ClaimActions.MapJsonKey(AbpClaimTypes.Role, "role");
options.ClaimActions.MapJsonKey(AbpClaimTypes.Email, "email");
options.ClaimActions.MapJsonKey(AbpClaimTypes.UserId, "sub");
options.ClaimActions.MapJsonKey(AbpClaimTypes.UserName, "name");
//TODO: Can we add claims types to AbpClaimTypes
options.ClaimActions.MapUniqueJsonKey("email_verified", "email_verified");
options.ClaimActions.MapUniqueJsonKey("phone_number", "phone_number");
options.ClaimActions.MapUniqueJsonKey("phone_number_verified", "phone_number_verified");
options.ClaimActions.MapAbpClaimTypes();
});
services.Configure<RemoteServiceOptions>(configuration);

17
src/Volo.Abp.AspNetCore.Authentication.OAuth/Microsoft/AspNetCore/Authentication/OAuth/Claims/AbpClaimActionCollectionExtensions.cs

@ -0,0 +1,17 @@
using Volo.Abp.Security.Claims;
namespace Microsoft.AspNetCore.Authentication.OAuth.Claims
{
public static class AbpClaimActionCollectionExtensions
{
public static void MapAbpClaimTypes(this ClaimActionCollection claimActions)
{
claimActions.MapJsonKey(AbpClaimTypes.Role, "role");
claimActions.MapJsonKey(AbpClaimTypes.Email, "email");
claimActions.MapJsonKey(AbpClaimTypes.UserName, "name");
claimActions.MapJsonKey(AbpClaimTypes.EmailVerified, "email_verified");
claimActions.MapJsonKey(AbpClaimTypes.PhoneNumber, "phone_number");
claimActions.MapJsonKey(AbpClaimTypes.PhoneNumberVerified, "phone_number_verified");
}
}
}

25
src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo.Abp.AspNetCore.Authentication.OAuth.csproj

@ -0,0 +1,25 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AssemblyName>Volo.Abp.AspNetCore.Authentication.OAuth</AssemblyName>
<PackageId>Volo.Abp.AspNetCore.Authentication.OAuth</PackageId>
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback>
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<RootNamespace />
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Volo.Abp.Core\Volo.Abp.Core.csproj" />
<ProjectReference Include="..\Volo.Abp.Security\Volo.Abp.Security.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.OAuth" Version="2.0.1" />
</ItemGroup>
</Project>

15
src/Volo.Abp.AspNetCore.Authentication.OAuth/Volo/Abp/AspNetCore/Authentication/OAuth/AbpAspNetCoreAuthenticationOAuthModule.cs

@ -0,0 +1,15 @@
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.Modularity;
using Volo.Abp.Security;
namespace Volo.Abp.AspNetCore.Authentication.OAuth
{
[DependsOn(typeof(AbpSecurityModule))]
public class AbpAspNetCoreAuthenticationOAuthModule : AbpModule
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddAssemblyOf<AbpAspNetCoreAuthenticationOAuthModule>();
}
}
}

20
src/Volo.Abp.Security/Volo/Abp/Security/Claims/AbpClaimTypes.cs

@ -2,33 +2,45 @@
namespace Volo.Abp.Security.Claims
{
//TODO: Instead of directly using static properties, can we just create an AbpClaimOptions and pass these values as defaults?
/// <summary>
/// Used to get ABP-specific claim type names.
/// </summary>
public static class AbpClaimTypes
{
/// <summary>
/// UserId.
/// Default: <see cref="ClaimTypes.Name"/>
/// </summary>
public static string UserName { get; set; } = ClaimTypes.Name;
/// <summary>
/// UserId.
/// Default: <see cref="ClaimTypes.NameIdentifier"/>
/// </summary>
public static string UserId { get; set; } = ClaimTypes.NameIdentifier;
/// <summary>
/// UserId.
/// Default: <see cref="ClaimTypes.Role"/>
/// </summary>
public static string Role { get; set; } = ClaimTypes.Role;
/// <summary>
/// UserId.
/// Default: <see cref="ClaimTypes.Email"/>
/// </summary>
public static string Email { get; set; } = ClaimTypes.Email;
/// <summary>
/// Default: "email_verified".
/// </summary>
public static string EmailVerified { get; set; } = "email_verified";
/// <summary>
/// Default: "phone_number".
/// </summary>
public static string PhoneNumber { get; set; } = "phone_number";
/// <summary>
/// Default: "phone_number_verified".
/// </summary>
public static string PhoneNumberVerified { get; set; } = "phone_number_verified";
}
}

Loading…
Cancel
Save