Skip to content

Commit 55e46dc

Browse files
Add Adobe IO provider (#573)
* Add AdobeIO package * Complete AdobeIO authentication * Update src/AspNet.Security.OAuth.AdobeIO/AspNet.Security.OAuth.AdobeIO.csproj Co-authored-by: Martin Costello <[email protected]> * Use commas to format scope, allows adding individual scopes properly. * Remove Endpoint paths. * Remove unnecessary scope. * Update readme with AdobeIO * Use OAuth-specific page for AdobeIO Co-authored-by: Martin Costello <[email protected]> * Use DefaultNetCoreTargetFramework * Add blank lines for readability. Co-authored-by: Martin Costello <[email protected]>
1 parent c4d9870 commit 55e46dc

10 files changed

+375
-0
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Notio
254254
EndProject
255255
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Mixcloud", "src\AspNet.Security.OAuth.Mixcloud\AspNet.Security.OAuth.Mixcloud.csproj", "{7A2EC21F-D411-4B45-AA3B-70143C1A9E2F}"
256256
EndProject
257+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.AdobeIO", "src\AspNet.Security.OAuth.AdobeIO\AspNet.Security.OAuth.AdobeIO.csproj", "{91BB9A49-9C88-4132-96E4-2D6148ACDE77}"
258+
EndProject
257259
Global
258260
GlobalSection(SolutionConfigurationPlatforms) = preSolution
259261
Debug|Any CPU = Debug|Any CPU
@@ -572,6 +574,10 @@ Global
572574
{7A2EC21F-D411-4B45-AA3B-70143C1A9E2F}.Debug|Any CPU.Build.0 = Debug|Any CPU
573575
{7A2EC21F-D411-4B45-AA3B-70143C1A9E2F}.Release|Any CPU.ActiveCfg = Release|Any CPU
574576
{7A2EC21F-D411-4B45-AA3B-70143C1A9E2F}.Release|Any CPU.Build.0 = Release|Any CPU
577+
{91BB9A49-9C88-4132-96E4-2D6148ACDE77}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
578+
{91BB9A49-9C88-4132-96E4-2D6148ACDE77}.Debug|Any CPU.Build.0 = Debug|Any CPU
579+
{91BB9A49-9C88-4132-96E4-2D6148ACDE77}.Release|Any CPU.ActiveCfg = Release|Any CPU
580+
{91BB9A49-9C88-4132-96E4-2D6148ACDE77}.Release|Any CPU.Build.0 = Release|Any CPU
575581
EndGlobalSection
576582
GlobalSection(SolutionProperties) = preSolution
577583
HideSolutionNode = FALSE
@@ -661,6 +667,7 @@ Global
661667
{C40ED377-E365-45FB-8B42-27BE82CC7BE3} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
662668
{DF2786DF-234D-4A8C-B166-0B8F8B7D527B} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
663669
{7A2EC21F-D411-4B45-AA3B-70143C1A9E2F} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
670+
{91BB9A49-9C88-4132-96E4-2D6148ACDE77} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
664671
EndGlobalSection
665672
GlobalSection(ExtensibilityGlobals) = postSolution
666673
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ We would love it if you could help contributing to this repository.
8989
* [zAfLu](https://github.com/zAfLu)
9090
* [zhengchun](https://github.com/zhengchun)
9191
* [Volodymyr Baydalka](https://github.com/zVolodymyr)
92+
* [Logan Dam](https://github.com/biltongza)
9293

9394
## Support
9495

@@ -111,6 +112,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
111112

112113
| Provider | Stable | Nightly | Documentation |
113114
|:-:|:-:|:-:|:-:|
115+
| AdobeIO | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.AdobeIO?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.AdobeIO/ "Download AspNet.Security.OAuth.AdobeIO from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.AdobeIO?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.AdobeIO "Download AspNet.Security.OAuth.AdobeIO from MyGet.org") | [Documentation](https://www.adobe.io/authentication/auth-methods.html#!AdobeDocs/adobeio-auth/master/AuthenticationOverview/OAuthIntegration.md "AdobeIO developer documentation") |
114116
| 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=true)](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") |
115117
| 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") |
116118
| 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") |
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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.AdobeIO
8+
{
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="AdobeIOAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class AdobeIOAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
public const string AccountType = "urn:adobeio:account_type";
17+
public const string EmailVerified = "urn:adobeio:email_verified";
18+
}
19+
}
20+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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.AdobeIO
11+
{
12+
public static class AdobeIOAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "AdobeIO";
18+
19+
/// <summary>
20+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
21+
/// </summary>
22+
public const string DisplayName = "AdobeIO";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
26+
/// </summary>
27+
public const string Issuer = "AdobeIO";
28+
29+
/// <summary>
30+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
31+
/// </summary>
32+
public const string CallbackPath = "/signin-adobeio";
33+
34+
/// <summary>
35+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
36+
/// </summary>
37+
public const string AuthorizationEndpoint = "https://ims-na1.adobelogin.com/ims/authorize/v2";
38+
39+
/// <summary>
40+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
41+
/// </summary>
42+
public const string TokenEndpoint = "https://ims-na1.adobelogin.com/ims/token";
43+
44+
/// <summary>
45+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
46+
/// </summary>
47+
public const string UserInformationEndpoint = "https://ims-na1.adobelogin.com/ims/userinfo/v2";
48+
}
49+
}
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.AdobeIO;
9+
using JetBrains.Annotations;
10+
using Microsoft.AspNetCore.Authentication;
11+
12+
namespace Microsoft.Extensions.DependencyInjection
13+
{
14+
/// <summary>
15+
/// Extension methods to add AdobeIO authentication capabilities to an HTTP application pipeline.
16+
/// </summary>
17+
public static class AdobeIOAuthenticationExtensions
18+
{
19+
/// <summary>
20+
/// Adds <see cref="AdobeIOAuthenticationHandler"/> to the specified
21+
/// <see cref="AuthenticationBuilder"/>, which enables AdobeIO authentication capabilities.
22+
/// </summary>
23+
/// <param name="builder">The authentication builder.</param>
24+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
25+
public static AuthenticationBuilder AddAdobeIO([NotNull] this AuthenticationBuilder builder)
26+
{
27+
return builder.AddAdobeIO(AdobeIOAuthenticationDefaults.AuthenticationScheme, options => { });
28+
}
29+
30+
/// <summary>
31+
/// Adds <see cref="AdobeIOAuthenticationHandler"/> to the specified
32+
/// <see cref="AuthenticationBuilder"/>, which enables AdobeIO 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 AddAdobeIO(
38+
[NotNull] this AuthenticationBuilder builder,
39+
[NotNull] Action<AdobeIOAuthenticationOptions> configuration)
40+
{
41+
return builder.AddAdobeIO(AdobeIOAuthenticationDefaults.AuthenticationScheme, configuration);
42+
}
43+
44+
/// <summary>
45+
/// Adds <see cref="AdobeIOAuthenticationHandler"/> to the specified
46+
/// <see cref="AuthenticationBuilder"/>, which enables AdobeIO 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 AdobeIO options.</param>
51+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
52+
public static AuthenticationBuilder AddAdobeIO(
53+
[NotNull] this AuthenticationBuilder builder,
54+
[NotNull] string scheme,
55+
[NotNull] Action<AdobeIOAuthenticationOptions> configuration)
56+
{
57+
return builder.AddAdobeIO(scheme, AdobeIOAuthenticationDefaults.DisplayName, configuration);
58+
}
59+
60+
/// <summary>
61+
/// Adds <see cref="AdobeIOAuthenticationHandler"/> to the specified
62+
/// <see cref="AuthenticationBuilder"/>, which enables AdobeIO 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 AdobeIO options.</param>
68+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
69+
public static AuthenticationBuilder AddAdobeIO(
70+
[NotNull] this AuthenticationBuilder builder,
71+
[NotNull] string scheme,
72+
[CanBeNull] string caption,
73+
[NotNull] Action<AdobeIOAuthenticationOptions> configuration)
74+
{
75+
return builder.AddOAuth<AdobeIOAuthenticationOptions, AdobeIOAuthenticationHandler>(scheme, caption, configuration);
76+
}
77+
}
78+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.Collections.Generic;
8+
using System.Linq;
9+
using System.Net.Http;
10+
using System.Net.Http.Headers;
11+
using System.Security.Claims;
12+
using System.Text.Encodings.Web;
13+
using System.Text.Json;
14+
using System.Threading.Tasks;
15+
using JetBrains.Annotations;
16+
using Microsoft.AspNetCore.Authentication;
17+
using Microsoft.AspNetCore.Authentication.OAuth;
18+
using Microsoft.AspNetCore.WebUtilities;
19+
using Microsoft.Extensions.Logging;
20+
using Microsoft.Extensions.Options;
21+
22+
namespace AspNet.Security.OAuth.AdobeIO
23+
{
24+
public class AdobeIOAuthenticationHandler : OAuthHandler<AdobeIOAuthenticationOptions>
25+
{
26+
public AdobeIOAuthenticationHandler(
27+
[NotNull] IOptionsMonitor<AdobeIOAuthenticationOptions> options,
28+
[NotNull] ILoggerFactory logger,
29+
[NotNull] UrlEncoder encoder,
30+
[NotNull] ISystemClock clock)
31+
: base(options, logger, encoder, clock)
32+
{
33+
}
34+
35+
protected override async Task<AuthenticationTicket> CreateTicketAsync(
36+
[NotNull] ClaimsIdentity identity,
37+
[NotNull] AuthenticationProperties properties,
38+
[NotNull] OAuthTokenResponse tokens)
39+
{
40+
string address = QueryHelpers.AddQueryString(Options.UserInformationEndpoint, "client_id", Options.ClientId);
41+
42+
using var request = new HttpRequestMessage(HttpMethod.Get, address);
43+
request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
44+
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", tokens.AccessToken);
45+
46+
using var response = await Backchannel.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, Context.RequestAborted);
47+
if (!response.IsSuccessStatusCode)
48+
{
49+
Logger.LogError("An error occurred while retrieving the user profile: the remote server " +
50+
"returned a {Status} response with the following payload: {Headers} {Body}.",
51+
/* Status: */ response.StatusCode,
52+
/* Headers: */ response.Headers.ToString(),
53+
/* Body: */ await response.Content.ReadAsStringAsync(Context.RequestAborted));
54+
55+
throw new HttpRequestException("An error occurred while retrieving the user profile.");
56+
}
57+
58+
using var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));
59+
60+
var principal = new ClaimsPrincipal(identity);
61+
var context = new OAuthCreatingTicketContext(principal, properties, Context, Scheme, Options, Backchannel, tokens, payload.RootElement);
62+
context.RunClaimActions();
63+
64+
await Options.Events.CreatingTicket(context);
65+
return new AuthenticationTicket(context.Principal!, context.Properties, Scheme.Name);
66+
}
67+
68+
/// <inheritdoc/>
69+
protected override string FormatScope([NotNull] IEnumerable<string> scopes)
70+
=> string.Join(',', scopes);
71+
}
72+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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.Security.Claims;
8+
using Microsoft.AspNetCore.Authentication;
9+
using Microsoft.AspNetCore.Authentication.OAuth;
10+
using static AspNet.Security.OAuth.AdobeIO.AdobeIOAuthenticationConstants;
11+
12+
namespace AspNet.Security.OAuth.AdobeIO
13+
{
14+
/// <summary>
15+
/// Defines a set of options used by <see cref="AdobeIOAuthenticationHandler"/>.
16+
/// </summary>
17+
public class AdobeIOAuthenticationOptions : OAuthOptions
18+
{
19+
public AdobeIOAuthenticationOptions()
20+
{
21+
ClaimsIssuer = AdobeIOAuthenticationDefaults.Issuer;
22+
CallbackPath = AdobeIOAuthenticationDefaults.CallbackPath;
23+
24+
AuthorizationEndpoint = AdobeIOAuthenticationDefaults.AuthorizationEndpoint;
25+
TokenEndpoint = AdobeIOAuthenticationDefaults.TokenEndpoint;
26+
UserInformationEndpoint = AdobeIOAuthenticationDefaults.UserInformationEndpoint;
27+
28+
Scope.Add("openid");
29+
Scope.Add("AdobeID");
30+
31+
ClaimActions.MapJsonKey(ClaimTypes.NameIdentifier, "sub");
32+
ClaimActions.MapJsonKey(ClaimTypes.Name, "name");
33+
ClaimActions.MapJsonKey(ClaimTypes.Email, "email");
34+
ClaimActions.MapJsonKey(ClaimTypes.GivenName, "given_name");
35+
ClaimActions.MapJsonKey(ClaimTypes.Surname, "family_name");
36+
ClaimActions.MapJsonSubKey(ClaimTypes.Country, "address", "country");
37+
ClaimActions.MapJsonKey(Claims.AccountType, "account_type");
38+
ClaimActions.MapJsonKey(Claims.EmailVerified, "email_verified");
39+
}
40+
}
41+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>$(DefaultNetCoreTargetFramework)</TargetFramework>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<Description>ASP.NET Core security middleware enabling AdobeIO authentication.</Description>
9+
<Authors>biltongza</Authors>
10+
<PackageTags>adobe;aspnetcore;authentication;oauth;security</PackageTags>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
15+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
16+
</ItemGroup>
17+
18+
</Project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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.Security.Claims;
8+
using System.Threading.Tasks;
9+
using Microsoft.AspNetCore.Authentication;
10+
using Microsoft.Extensions.DependencyInjection;
11+
using Xunit;
12+
using Xunit.Abstractions;
13+
14+
namespace AspNet.Security.OAuth.AdobeIO
15+
{
16+
public class AdobeIOTests : OAuthTests<AdobeIOAuthenticationOptions>
17+
{
18+
public AdobeIOTests(ITestOutputHelper outputHelper)
19+
{
20+
OutputHelper = outputHelper;
21+
}
22+
23+
public override string DefaultScheme => AdobeIOAuthenticationDefaults.AuthenticationScheme;
24+
25+
protected internal override void RegisterAuthentication(AuthenticationBuilder builder)
26+
{
27+
builder.AddAdobeIO(options =>
28+
{
29+
ConfigureDefaults(builder, options);
30+
});
31+
}
32+
33+
[Theory]
34+
[InlineData(ClaimTypes.NameIdentifier, "B0DC108C5CD449CA0A494133@c62f24cc5b5b7e0e0a494004")]
35+
[InlineData(ClaimTypes.Name, "John Sample")]
36+
[InlineData(ClaimTypes.Email, "[email protected]")]
37+
[InlineData(ClaimTypes.GivenName, "John")]
38+
[InlineData(ClaimTypes.Surname, "Sample")]
39+
[InlineData(ClaimTypes.Country, "US")]
40+
[InlineData("urn:adobeio:account_type", "ent")]
41+
[InlineData("urn:adobeio:email_verified", "True")]
42+
public async Task Can_Sign_In_Using_AdobeIO(string claimType, string claimValue)
43+
{
44+
// Arrange
45+
using var server = CreateTestServer();
46+
47+
// Act
48+
var claims = await AuthenticateUserAsync(server);
49+
50+
// Assert
51+
AssertClaim(claims, claimType, claimValue);
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)