Skip to content

Commit bf24248

Browse files
authored
Add DigitalOcean provider (#653)
* Add DigitalOcean oAuth Provider * Add tests * Update src/AspNet.Security.OAuth.DigitalOcean/AspNet.Security.OAuth.DigitalOcean.csproj * Update src/AspNet.Security.OAuth.DigitalOcean/AspNet.Security.OAuth.DigitalOcean.csproj * Update DigitalOceanAuthenticationHandler.cs * PR Feedback * Update AspNet.Security.OAuth.DigitalOcean.csproj * Consume scope constant and remove ResponseType constant * Revert indenting
1 parent 1347eb2 commit bf24248

12 files changed

+472
-1
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{C2CA4B38-A
188188
docs\amocrm.md = docs\amocrm.md
189189
docs\battlenet.md = docs\battlenet.md
190190
docs\bitbucket.md = docs\bitbucket.md
191+
docs\digitalocean.md = docs\digitalocean.md
191192
docs\discord.md = docs\discord.md
192193
docs\dropbox.md = docs\dropbox.md
193194
docs\ebay.md = docs\ebay.md
@@ -269,12 +270,14 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Ebay"
269270
EndProject
270271
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.ServiceChannel", "src\AspNet.Security.OAuth.ServiceChannel\AspNet.Security.OAuth.ServiceChannel.csproj", "{57633BE6-C7AD-4197-A75A-F38A2312A4D9}"
271272
EndProject
272-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspNet.Security.OAuth.Trovo", "src\AspNet.Security.OAuth.Trovo\AspNet.Security.OAuth.Trovo.csproj", "{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}"
273+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Trovo", "src\AspNet.Security.OAuth.Trovo\AspNet.Security.OAuth.Trovo.csproj", "{DC804C6D-3774-4FA7-8EA6-8C8198995BD6}"
273274
EndProject
274275
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Twitter", "src\AspNet.Security.OAuth.Twitter\AspNet.Security.OAuth.Twitter.csproj", "{82314BA9-8AB2-46B9-AB12-9109619B8331}"
275276
EndProject
276277
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Xero", "src\AspNet.Security.OAuth.Xero\AspNet.Security.OAuth.Xero.csproj", "{1F869094-FAC8-49B5-92A4-706C028CDF93}"
277278
EndProject
279+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.DigitalOcean", "src\AspNet.Security.OAuth.DigitalOcean\AspNet.Security.OAuth.DigitalOcean.csproj", "{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593}"
280+
EndProject
278281
Global
279282
GlobalSection(SolutionConfigurationPlatforms) = preSolution
280283
Debug|Any CPU = Debug|Any CPU
@@ -625,6 +628,10 @@ Global
625628
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Debug|Any CPU.Build.0 = Debug|Any CPU
626629
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Release|Any CPU.ActiveCfg = Release|Any CPU
627630
{1F869094-FAC8-49B5-92A4-706C028CDF93}.Release|Any CPU.Build.0 = Release|Any CPU
631+
{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
632+
{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593}.Debug|Any CPU.Build.0 = Debug|Any CPU
633+
{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593}.Release|Any CPU.ActiveCfg = Release|Any CPU
634+
{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593}.Release|Any CPU.Build.0 = Release|Any CPU
628635
EndGlobalSection
629636
GlobalSection(SolutionProperties) = preSolution
630637
HideSolutionNode = FALSE
@@ -722,6 +729,7 @@ Global
722729
{DC804C6D-3774-4FA7-8EA6-8C8198995BD6} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
723730
{82314BA9-8AB2-46B9-AB12-9109619B8331} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
724731
{1F869094-FAC8-49B5-92A4-706C028CDF93} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
732+
{FAE6E4C3-5A0D-45A5-9D17-57F4F6DA2593} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
725733
EndGlobalSection
726734
GlobalSection(ExtensibilityGlobals) = postSolution
727735
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ We would love it if you could help contributing to this repository.
5555
* [CoCo Lin](https://github.com/linmasaki)
5656
* [Dave Timmins](https://github.com/davetimmins)
5757
* [Dmitry Popov](https://github.com/justdmitry)
58+
* [Elan Hasson](https://github.com/ElanHasson)
5859
* [Eric Green](https://github.com/ericgreenmix)
5960
* [Ethan Celletti](https://github.com/Gekctek)
6061
* [Floris Westerman](https://github.com/FWest98)
@@ -134,6 +135,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
134135
| Coinbase | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Coinbase?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Coinbase/ "Download AspNet.Security.OAuth.Coinbase from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Coinbase?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Coinbase "Download AspNet.Security.OAuth.Coinbase from MyGet.org") | [Documentation](https://developers.coinbase.com/docs/wallet/coinbase-connect/integrating "Coinbase developer documentation") |
135136
| DeviantArt | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.DeviantArt?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.DeviantArt/ "Download AspNet.Security.OAuth.DeviantArt from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.DeviantArt?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.DeviantArt "Download AspNet.Security.OAuth.DeviantArt from MyGet.org") | [Documentation](https://www.deviantart.com/developers/ "DeviantArt developer documentation") |
136137
| Deezer | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Deezer?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Deezer/ "Download AspNet.Security.OAuth.Deezer from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Deezer?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Deezer "Download AspNet.Security.OAuth.Deezer from MyGet.org") | [Documentation](https://developers.deezer.com/api/oauth "Deezer developer documentation") |
138+
| DigitalOcean | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.DigitalOcean?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.DigitalOcean/ "Download AspNet.Security.OAuth.DigitalOcean from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.DigitalOcean?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.DigitalOcean "Download AspNet.Security.OAuth.DigitalOcean from MyGet.org") | [Documentation](https://docs.digitalocean.com/reference/api/oauth-api/ "DigitalOcean developer documentation") |
137139
| Discord | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Discord?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Discord/ "Download AspNet.Security.OAuth.Discord from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Discord?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Discord "Download AspNet.Security.OAuth.Discord from MyGet.org") | [Documentation](https://discord.com/developers/docs/topics/oauth2 "Discord developer documentation") |
138140
| Dropbox | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Dropbox?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Dropbox/ "Download AspNet.Security.OAuth.Dropbox from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Dropbox?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Dropbox "Download AspNet.Security.OAuth.Dropbox from MyGet.org") | [Documentation](https://www.dropbox.com/developers/reference/oauth-guide?_tk=guides_lp&_ad=deepdive2&_camp=oauth "Dropbox developer documentation") |
139141
| eBay | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Ebay?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Ebay/ "Download AspNet.Security.OAuth.Ebay from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Ebay?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Ebay "Download AspNet.Security.OAuth.Ebay from MyGet.org") | [Documentation](https://developer.ebay.com/api-docs/static/oauth-tokens.html "eBay developer documentation") |

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ covered by the section above.
4646
| Apple | **Required** | [Documentation](sign-in-with-apple.md "Apple provider documentation") |
4747
| BattleNet | **Required** | [Documentation](battlenet.md "BattleNet provider documentation") |
4848
| Bitbucket | _Optional_ | [Documentation](bitbucket.md "Bitbucket provider documentation") |
49+
| DigitalOcean | _Optional_ | [Documentation](digitalocean.md "DigitalOcean provider documentation") |
4950
| Discord | _Optional_ | [Documentation](discord.md "Discord provider documentation") |
5051
| eBay | **Required** | [Documentation](ebay.md "eBay provider documentation") |
5152
| EVEOnline | _Optional_ | [Documentation](eveonline.md "EVEOnline provider documentation") |

docs/digitalocean.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Integrating the DigitalOcean Provider
2+
3+
## Example
4+
5+
```csharp
6+
services.AddAuthentication(options => /* Auth configuration */)
7+
.AddDigitalOcean(options =>
8+
{
9+
options.ClientId = "my-client-id";
10+
options.ClientSecret = "my-client-secret";
11+
});
12+
```
13+
14+
## Required Additional Settings
15+
16+
_None._
17+
18+
## Optional Settings
19+
20+
_None._
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageValidationBaselineVersion>6.0.4</PackageValidationBaselineVersion>
5+
<TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks>
6+
</PropertyGroup>
7+
8+
<!-- TODO Remove once published to NuGet.org -->
9+
<PropertyGroup>
10+
<DisablePackageBaselineValidation>true</DisablePackageBaselineValidation>
11+
</PropertyGroup>
12+
13+
<PropertyGroup>
14+
<Description>ASP.NET Core security middleware enabling DigitalOcean authentication.</Description>
15+
<Authors>Elan Hasson</Authors>
16+
<PackageTags>DigitalOcean;aspnetcore;authentication;oauth;security</PackageTags>
17+
</PropertyGroup>
18+
19+
<ItemGroup>
20+
<FrameworkReference Include="Microsoft.AspNetCore.App" />
21+
<PackageReference Include="JetBrains.Annotations" PrivateAssets="All" />
22+
</ItemGroup>
23+
24+
</Project>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.DigitalOcean;
8+
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="DigitalOceanAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class DigitalOceanAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
/// <summary>
17+
/// The claim for determining if the user's email address has been verified.
18+
/// </summary>
19+
public const string EmailVerified = "urn:digitalocean:email_verified";
20+
}
21+
22+
/// <summary>
23+
/// DigitalOcean API Scopes
24+
/// <para>https://docs.digitalocean.com/reference/api/oauth-api/</para>
25+
/// </summary>
26+
public static class Scopes
27+
{
28+
/// <summary>
29+
/// Read Access to the DigitalOcean account.
30+
/// <para>Default scope</para>
31+
/// </summary>
32+
public const string Read = "read";
33+
34+
/// <summary>
35+
/// Write Access to the DigitalOcean account.
36+
/// </summary>
37+
public const string Write = "write";
38+
}
39+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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.DigitalOcean;
8+
9+
/// <summary>
10+
/// Default values used by the DigitalOcean authentication middleware.
11+
/// </summary>
12+
public static class DigitalOceanAuthenticationDefaults
13+
{
14+
/// <summary>
15+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
16+
/// </summary>
17+
public const string AuthenticationScheme = "DigitalOcean";
18+
19+
/// <summary>
20+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
21+
/// </summary>
22+
public static readonly string DisplayName = "DigitalOcean";
23+
24+
/// <summary>
25+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
26+
/// </summary>
27+
public static readonly string Issuer = "DigitalOcean";
28+
29+
/// <summary>
30+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
31+
/// </summary>
32+
public static readonly string CallbackPath = "/signin-digitalocean";
33+
34+
/// <summary>
35+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
36+
/// </summary>
37+
public static readonly string AuthorizationEndpoint = "https://cloud.digitalocean.com/v1/oauth/authorize";
38+
39+
/// <summary>
40+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
41+
/// </summary>
42+
public static readonly string TokenEndpoint = "https://cloud.digitalocean.com/v1/oauth/token";
43+
44+
/// <summary>
45+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
46+
/// </summary>
47+
public static readonly string UserInformationEndpoint = "https://api.digitalocean.com/v2/account";
48+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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 AspNet.Security.OAuth.DigitalOcean;
8+
9+
namespace Microsoft.Extensions.DependencyInjection;
10+
11+
/// <summary>
12+
/// Extension methods to add DigitalOcean authentication capabilities to an HTTP application pipeline.
13+
/// </summary>
14+
public static class DigitalOceanAuthenticationExtensions
15+
{
16+
/// <summary>
17+
/// Adds <see cref="DigitalOceanAuthenticationHandler"/> to the specified
18+
/// <see cref="AuthenticationBuilder"/>, which enables DigitalOcean authentication capabilities.
19+
/// </summary>
20+
/// <param name="builder">The authentication builder.</param>
21+
/// <returns>A reference to this instance after the operation has completed.</returns>
22+
public static AuthenticationBuilder AddDigitalOcean([NotNull] this AuthenticationBuilder builder)
23+
{
24+
return builder.AddDigitalOcean(DigitalOceanAuthenticationDefaults.AuthenticationScheme, options => { });
25+
}
26+
27+
/// <summary>
28+
/// Adds <see cref="DigitalOceanAuthenticationHandler"/> to the specified
29+
/// <see cref="AuthenticationBuilder"/>, which enables DigitalOcean authentication capabilities.
30+
/// </summary>
31+
/// <param name="builder">The authentication builder.</param>
32+
/// <param name="configuration">The delegate used to configure the OpenID 2.0 options.</param>
33+
/// <returns>A reference to this instance after the operation has completed.</returns>
34+
public static AuthenticationBuilder AddDigitalOcean(
35+
[NotNull] this AuthenticationBuilder builder,
36+
[NotNull] Action<DigitalOceanAuthenticationOptions> configuration)
37+
{
38+
return builder.AddDigitalOcean(DigitalOceanAuthenticationDefaults.AuthenticationScheme, configuration);
39+
}
40+
41+
/// <summary>
42+
/// Adds <see cref="DigitalOceanAuthenticationHandler"/> to the specified
43+
/// <see cref="AuthenticationBuilder"/>, which enables DigitalOcean authentication capabilities.
44+
/// </summary>
45+
/// <param name="builder">The authentication builder.</param>
46+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
47+
/// <param name="configuration">The delegate used to configure the DigitalOcean options.</param>
48+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
49+
public static AuthenticationBuilder AddDigitalOcean(
50+
[NotNull] this AuthenticationBuilder builder,
51+
[NotNull] string scheme,
52+
[NotNull] Action<DigitalOceanAuthenticationOptions> configuration)
53+
{
54+
return builder.AddDigitalOcean(scheme, DigitalOceanAuthenticationDefaults.DisplayName, configuration);
55+
}
56+
57+
/// <summary>
58+
/// Adds <see cref="DigitalOceanAuthenticationHandler"/> to the specified
59+
/// <see cref="AuthenticationBuilder"/>, which enables DigitalOcean authentication capabilities.
60+
/// </summary>
61+
/// <param name="builder">The authentication builder.</param>
62+
/// <param name="scheme">The authentication scheme associated with this instance.</param>
63+
/// <param name="caption">The optional display name associated with this instance.</param>
64+
/// <param name="configuration">The delegate used to configure the DigitalOcean options.</param>
65+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
66+
public static AuthenticationBuilder AddDigitalOcean(
67+
[NotNull] this AuthenticationBuilder builder,
68+
[NotNull] string scheme,
69+
[CanBeNull] string caption,
70+
[NotNull] Action<DigitalOceanAuthenticationOptions> configuration)
71+
{
72+
return builder.AddOAuth<DigitalOceanAuthenticationOptions, DigitalOceanAuthenticationHandler>(scheme, caption, configuration);
73+
}
74+
}

0 commit comments

Comments
 (0)