Skip to content

Commit bb7878a

Browse files
authored
Add Alipay provider (#522)
* Add Alipay provider * Add unit testing for Alipay * Update README.md * Fix test uri * Update by suggestions of review. * Use explicit type instead of var
1 parent e9a78d7 commit bb7878a

10 files changed

+536
-1
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Kakao
204204
EndProject
205205
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Lichess", "src\AspNet.Security.OAuth.Lichess\AspNet.Security.OAuth.Lichess.csproj", "{26DDE1D4-45D5-4CAA-ACB6-71FECF781B27}"
206206
EndProject
207-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.AmoCrm", "src\AspNet.Security.OAuth.AmoCrm\AspNet.Security.OAuth.AmoCrm.csproj", "{DDF7546B-51C4-46EB-B102-7EE720E8E74F}"
207+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.AmoCrm", "src\AspNet.Security.OAuth.AmoCrm\AspNet.Security.OAuth.AmoCrm.csproj", "{DDF7546B-51C4-46EB-B102-7EE720E8E74F}"
208+
EndProject
209+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Alipay", "src\AspNet.Security.OAuth.Alipay\AspNet.Security.OAuth.Alipay.csproj", "{61AB67B0-0F4A-47A2-A4D8-9738AA34C468}"
208210
EndProject
209211
Global
210212
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -488,6 +490,10 @@ Global
488490
{DDF7546B-51C4-46EB-B102-7EE720E8E74F}.Debug|Any CPU.Build.0 = Debug|Any CPU
489491
{DDF7546B-51C4-46EB-B102-7EE720E8E74F}.Release|Any CPU.ActiveCfg = Release|Any CPU
490492
{DDF7546B-51C4-46EB-B102-7EE720E8E74F}.Release|Any CPU.Build.0 = Release|Any CPU
493+
{61AB67B0-0F4A-47A2-A4D8-9738AA34C468}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
494+
{61AB67B0-0F4A-47A2-A4D8-9738AA34C468}.Debug|Any CPU.Build.0 = Debug|Any CPU
495+
{61AB67B0-0F4A-47A2-A4D8-9738AA34C468}.Release|Any CPU.ActiveCfg = Release|Any CPU
496+
{61AB67B0-0F4A-47A2-A4D8-9738AA34C468}.Release|Any CPU.Build.0 = Release|Any CPU
491497
EndGlobalSection
492498
GlobalSection(SolutionProperties) = preSolution
493499
HideSolutionNode = FALSE
@@ -568,6 +574,7 @@ Global
568574
{1B19314C-9F33-4E71-AF0C-46ED8AB621CE} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
569575
{26DDE1D4-45D5-4CAA-ACB6-71FECF781B27} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
570576
{DDF7546B-51C4-46EB-B102-7EE720E8E74F} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
577+
{61AB67B0-0F4A-47A2-A4D8-9738AA34C468} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
571578
EndGlobalSection
572579
GlobalSection(ExtensibilityGlobals) = postSolution
573580
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ We would love it if you could help contributing to this repository.
6666
* [Jordan Knight](https://github.com/jakkaj)
6767
* [Kévin Chalet](https://github.com/kevinchalet)
6868
* [Konstantin Mamaev](https://github.com/MrMeison)
69+
* [LeaFrock](https://github.com/LeaFrock)
6970
* [Luke Fulliton](https://github.com/lukefulliton)
7071
* [Mariusz Zieliński](https://github.com/mariozski)
7172
* [Martin Costello](https://github.com/martincostello)
@@ -110,6 +111,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
110111

111112
| Provider | Stable | Nightly | Documentation |
112113
|:-:|:-:|:-:|:-:|
114+
| Alipay | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Alipay?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Alipay/ "Download AspNet.Security.OAuth.Alipay from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Alipay?includePreReleases=false)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Alipay "Download AspNet.Security.OAuth.Alipay from MyGet.org") | [Documentation](https://opendocs.alipay.com/open/01emu5 "Alipay developer documentation") |
113115
| Amazon | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Amazon?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Amazon/ "Download AspNet.Security.OAuth.Amazon from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Amazon?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Amazon "Download AspNet.Security.OAuth.Amazon from MyGet.org") | [Documentation](https://developer.amazon.com/docs/login-with-amazon/documentation-overview.html "Amazon developer documentation") |
114116
| amoCRM | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.AmoCrm?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.AmoCrm/ "Download AspNet.Security.OAuth.AmoCrm from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.AmoCrm?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.AmoCrm "Download AspNet.Security.OAuth.AmoCrm from MyGet.org") | [Documentation](https://www.amocrm.com/developers/content/oauth/step-by-step/ "amoCRM developer documentation") |
115117
| Apple | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Apple?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Apple/ "Download AspNet.Security.OAuth.Apple from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Apple?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Apple "Download AspNet.Security.OAuth.Apple from MyGet.org") | [Documentation](https://developer.apple.com/documentation/signinwithapplerestapi "Apple developer documentation") |
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
namespace AspNet.Security.OAuth.Alipay
8+
{
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="AlipayAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class AlipayAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
public const string Avatar = "urn:alipay:avatar";
17+
18+
public const string Province = "urn:alipay:province";
19+
20+
public const string City = "urn:alipay:city";
21+
22+
public const string Nickname = "urn:alipay:nick_name";
23+
24+
/// <summary>
25+
/// The user's gender. F: Female; M: Male.
26+
/// </summary>
27+
public const string Gender = "urn:alipay:gender";
28+
}
29+
}
30+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using Microsoft.AspNetCore.Authentication;
8+
using Microsoft.AspNetCore.Authentication.OAuth;
9+
10+
namespace AspNet.Security.OAuth.Alipay
11+
{
12+
/// <summary>
13+
/// Default values for Alipay authentication.
14+
/// </summary>
15+
public static class AlipayAuthenticationDefaults
16+
{
17+
/// <summary>
18+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
19+
/// </summary>
20+
public const string AuthenticationScheme = "Alipay";
21+
22+
/// <summary>
23+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
24+
/// </summary>
25+
public const string DisplayName = "Alipay";
26+
27+
/// <summary>
28+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
29+
/// </summary>
30+
public const string Issuer = "Alipay";
31+
32+
/// <summary>
33+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
34+
/// </summary>
35+
public const string CallbackPath = "/signin-alipay";
36+
37+
/// <summary>
38+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
39+
/// </summary>
40+
public const string AuthorizationEndpoint = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm";
41+
42+
/// <summary>
43+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
44+
/// </summary>
45+
public const string TokenEndpoint = "https://openapi.alipay.com/gateway.do";
46+
47+
/// <summary>
48+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
49+
/// </summary>
50+
public const string UserInformationEndpoint = "https://openapi.alipay.com/gateway.do";
51+
}
52+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3+
* See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers
4+
* for more information concerning the license and the contributors participating to this project.
5+
*/
6+
7+
using System;
8+
using AspNet.Security.OAuth.Alipay;
9+
using JetBrains.Annotations;
10+
using Microsoft.AspNetCore.Authentication;
11+
12+
namespace Microsoft.Extensions.DependencyInjection
13+
{
14+
/// <summary>
15+
/// Extension methods to add Alipay authentication capabilities to an HTTP application pipeline.
16+
/// </summary>
17+
public static class AlipayAuthenticationExtensions
18+
{
19+
/// <summary>
20+
/// Adds <see cref="AlipayAuthenticationHandler"/> to the specified
21+
/// <see cref="AuthenticationBuilder"/>, which enables Alipay authentication capabilities.
22+
/// </summary>
23+
/// <param name="builder">The authentication builder.</param>
24+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
25+
public static AuthenticationBuilder AddAlipay([NotNull] this AuthenticationBuilder builder)
26+
{
27+
return builder.AddAlipay(AlipayAuthenticationDefaults.AuthenticationScheme, options => { });
28+
}
29+
30+
/// <summary>
31+
/// Adds <see cref="AlipayAuthenticationHandler"/> to the specified
32+
/// <see cref="AuthenticationBuilder"/>, which enables Alipay authentication capabilities.
33+
/// </summary>
34+
/// <param name="builder">The authentication builder.</param>
35+
/// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param>
36+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
37+
public static AuthenticationBuilder AddAlipay(
38+
[NotNull] this AuthenticationBuilder builder,
39+
[NotNull] Action<AlipayAuthenticationOptions> configuration)
40+
{
41+
return builder.AddAlipay(AlipayAuthenticationDefaults.AuthenticationScheme, configuration);
42+
}
43+
44+
/// <summary>
45+
/// Adds <see cref="AlipayAuthenticationHandler"/> to the specified
46+
/// <see cref="AuthenticationBuilder"/>, which enables Alipay authentication capabilities.
47+
/// </summary>
48+
/// <param name="builder">The authentication builder.</param>
49+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
50+
/// <param name="configuration">The delegate used to configure the Alipay options.</param>
51+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
52+
public static AuthenticationBuilder AddAlipay(
53+
[NotNull] this AuthenticationBuilder builder,
54+
[NotNull] string scheme,
55+
[NotNull] Action<AlipayAuthenticationOptions> configuration)
56+
{
57+
return builder.AddAlipay(scheme, AlipayAuthenticationDefaults.DisplayName, configuration);
58+
}
59+
60+
/// <summary>
61+
/// Adds <see cref="AlipayAuthenticationHandler"/> to the specified
62+
/// <see cref="AuthenticationBuilder"/>, which enables Alipay authentication capabilities.
63+
/// </summary>
64+
/// <param name="builder">The authentication builder.</param>
65+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
66+
/// <param name="caption">The optional display name associated with this instance.</param>
67+
/// <param name="configuration">The delegate used to configure the Alipay options.</param>
68+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
69+
public static AuthenticationBuilder AddAlipay(
70+
[NotNull] this AuthenticationBuilder builder,
71+
[NotNull] string scheme,
72+
[CanBeNull] string caption,
73+
[NotNull] Action<AlipayAuthenticationOptions> configuration)
74+
{
75+
return builder.AddOAuth<AlipayAuthenticationOptions, AlipayAuthenticationHandler>(scheme, caption, configuration);
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)