Skip to content

Commit e09e4ca

Browse files
authored
Add Kloudless provider (#479)
* WIP : Add kloudless provider * Add kloudless provider * Add entry in readme * Add commented example * Add more unit tests. Explicit error * Fix exception usage * Add missing punctuation * Add kloudless doc. Specify default scope and add possible scopes. * remove example in MVC project * Fix convention issue on constant. Add comment.
1 parent 985f785 commit e09e4ca

12 files changed

+484
-0
lines changed

AspNet.Security.OAuth.Providers.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{
198198
.github\workflows\build.yml = .github\workflows\build.yml
199199
EndProjectSection
200200
EndProject
201+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.Security.OAuth.Kloudless", "src\AspNet.Security.OAuth.Kloudless\AspNet.Security.OAuth.Kloudless.csproj", "{947E1C60-BCE1-402E-9E5A-6D7094A68DE9}"
202+
EndProject
201203
Global
202204
GlobalSection(SolutionConfigurationPlatforms) = preSolution
203205
Debug|Any CPU = Debug|Any CPU
@@ -464,6 +466,10 @@ Global
464466
{F8A4A5C4-86D9-4CF2-A2FC-3B46CCC51750}.Debug|Any CPU.Build.0 = Debug|Any CPU
465467
{F8A4A5C4-86D9-4CF2-A2FC-3B46CCC51750}.Release|Any CPU.ActiveCfg = Release|Any CPU
466468
{F8A4A5C4-86D9-4CF2-A2FC-3B46CCC51750}.Release|Any CPU.Build.0 = Release|Any CPU
469+
{947E1C60-BCE1-402E-9E5A-6D7094A68DE9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
470+
{947E1C60-BCE1-402E-9E5A-6D7094A68DE9}.Debug|Any CPU.Build.0 = Debug|Any CPU
471+
{947E1C60-BCE1-402E-9E5A-6D7094A68DE9}.Release|Any CPU.ActiveCfg = Release|Any CPU
472+
{947E1C60-BCE1-402E-9E5A-6D7094A68DE9}.Release|Any CPU.Build.0 = Release|Any CPU
467473
EndGlobalSection
468474
GlobalSection(SolutionProperties) = preSolution
469475
HideSolutionNode = FALSE
@@ -540,6 +546,7 @@ Global
540546
{286D1FB0-716C-47CB-A519-22E1D34DFDF7} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
541547
{F8A4A5C4-86D9-4CF2-A2FC-3B46CCC51750} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
542548
{B1792D2A-6D6C-4484-968E-D68DF376BA40} = {3FA3F7B5-5373-4E43-8F45-8EC18249E526}
549+
{947E1C60-BCE1-402E-9E5A-6D7094A68DE9} = {C1352FD3-AE8B-43EE-B45B-F6E0B3FBAC6D}
543550
EndGlobalSection
544551
GlobalSection(ExtensibilityGlobals) = postSolution
545552
SolutionGuid = {C7B54DE2-6407-4802-AD9C-CE54BF414C8C}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ If a provider you're looking for does not exist, consider making a PR to add one
137137
| HealthGraph (Runkeeper) | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.HealthGraph?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.HealthGraph/ "Download AspNet.Security.OAuth.HealthGraph from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.HealthGraph?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.HealthGraph "Download AspNet.Security.OAuth.HealthGraph from MyGet.org") | N/A |
138138
| Imgur | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Imgur?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Imgur/ "Download AspNet.Security.OAuth.Imgur from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Imgur?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Imgur "Download AspNet.Security.OAuth.Imgur from MyGet.org") | [Documentation](https://apidocs.imgur.com/?version=latest#authorization-and-oauth "Imgur developer documentation") |
139139
| Instagram | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Instagram?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Instagram/ "Download AspNet.Security.OAuth.Instagram from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Instagram?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Instagram "Download AspNet.Security.OAuth.Instagram from MyGet.org") | [Documentation](https://www.instagram.com/developer/authentication/ "Instagram developer documentation") |
140+
| Kloudless | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.Kloudless?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.Kloudless/ "Download AspNet.Security.OAuth.Kloudless from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.Kloudless?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.Kloudless "Download AspNet.Security.OAuth.Kloudless from MyGet.org") | [Documentation](https://developers.kloudless.com/docs/v1/authentication "Kloudless developer documentation") |
140141
| LinkedIn | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.LinkedIn?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.LinkedIn/ "Download AspNet.Security.OAuth.LinkedIn from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.LinkedIn?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.LinkedIn "Download AspNet.Security.OAuth.LinkedIn from MyGet.org") | [Documentation](https://docs.microsoft.com/en-us/linkedin/shared/authentication/authentication "LinkedIn developer documentation") |
141142
| MailChimp | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.MailChimp?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.MailChimp/ "Download AspNet.Security.OAuth.MailChimp from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.MailChimp?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.MailChimp "Download AspNet.Security.OAuth.MailChimp from MyGet.org") | [Documentation](https://developer.mailchimp.com/documentation/mailchimp/guides/how-to-use-oauth2/ "MailChimp developer documentation") |
142143
| MailRu | [![NuGet](https://buildstats.info/nuget/AspNet.Security.OAuth.MailRu?includePreReleases=false)](https://www.nuget.org/packages/AspNet.Security.OAuth.MailRu/ "Download AspNet.Security.OAuth.MailRu from NuGet.org") | [![MyGet](https://buildstats.info/myget/aspnet-contrib/AspNet.Security.OAuth.MailRu?includePreReleases=true)](https://www.myget.org/feed/aspnet-contrib/package/nuget/AspNet.Security.OAuth.MailRu "Download AspNet.Security.OAuth.MailRu from MyGet.org") | [Documentation](https://o2.mail.ru/docs#web "MailRu developer documentation") |

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ covered by the section above.
5252
| GitHub | _Optional_ | [Documentation](github.md "GitHub provider documentation") |
5353
| Gitee | _Optional_ | [Documentation](gitee.md "Gitee provider documentation") |
5454
| Instagram | _Optional_ | [Documentation](instagram.md "Instagram provider documentation") |
55+
| Kloudless | _Optional_ | [Documentation](kloudless.md "Kloudless provider documentation") |
5556
| LinkedIn | _Optional_ | [Documentation](linkedin.md "LinkedIn provider documentation") |
5657
| Odnoklassniki | _Optional_ | [Documentation](odnoklassniki.md "Odnoklassniki provider documentation") |
5758
| Okta | **Required** | [Documentation](okta.md "Okta provider documentation") |

docs/kloudless.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Integrating the Kloudless Provider
2+
3+
## Example
4+
5+
```csharp
6+
services.AddAuthentication(options => /* Auth configuration */)
7+
.AddKloudless(options =>
8+
{
9+
options.ClientId = "my-client-id";
10+
options.ClientSecret = "my-client-secret";
11+
12+
options.Scope.Clear();
13+
options.Scope.Add(KloudlessAuthenticationConstants.Scopes.Calendar);
14+
});
15+
```
16+
17+
## Required Additional Settings
18+
19+
_None._
20+
21+
## Optional Settings
22+
23+
| Property Name | Property Type | Description | Default Value |
24+
|:--|:--|:--|:--|
25+
| `Scope` | `string` | The scope you want to use on kloudless, see [documentation](https://developers.kloudless.com/guides/kb/scopes.html "List of possible scopes"). | `KloudlessAuthenticationConstants.Scopes.Any` |
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+
<TargetFrameworks>netcoreapp3.1</TargetFrameworks>
5+
</PropertyGroup>
6+
7+
<PropertyGroup>
8+
<Description>ASP.NET Core security middleware enabling Kloudless authentication.</Description>
9+
<Authors>Yann ROBIN</Authors>
10+
<PackageTags>aspnetcore;authentication;kloudless;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: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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.Kloudless
8+
{
9+
/// <summary>
10+
/// Contains constants specific to the <see cref="KloudlessAuthenticationHandler"/>.
11+
/// </summary>
12+
public static class KloudlessAuthenticationConstants
13+
{
14+
public static class Claims
15+
{
16+
public const string Account = "urn:kloudless:account";
17+
public const string Created = "urn:kloudless:created";
18+
public const string Modified = "urn:kloudless:modified";
19+
public const string Service = "urn:kloudless:service";
20+
public const string ServiceName = "urn:kloudless:service_name";
21+
public const string Admin = "urn:kloudless:admin";
22+
public const string InternalUse = "urn:kloudless:internal_use";
23+
public const string Api = "urn:kloudless:api";
24+
public const string Apis = "urn:kloudless:apis";
25+
public const string EffectiveScope = "urn:kloudless:effective_scope";
26+
public const string Type = "urn:kloudless:type";
27+
public const string Enabled = "urn:kloudless:enabled";
28+
public const string ObjectDefinitions = "urn:kloudless:object_definitions";
29+
public const string CustomProperties = "urn:kloudless:custom_properties";
30+
public const string ProxyConnection = "urn:kloudless:proxy_connection";
31+
public const string Active = "urn:kloudless:active";
32+
}
33+
34+
/// <summary>
35+
/// Kloudless API Scopes
36+
/// <para>https://developers.kloudless.com/guides/kb/scopes.html</para>
37+
/// </summary>
38+
public static class Scopes
39+
{
40+
/// <summary>
41+
/// Use all available services in kloudless
42+
/// <para>Default scope</para>
43+
/// </summary>
44+
public const string Any = "any";
45+
46+
/// <summary>
47+
/// Cloud Storage API category
48+
/// </summary>
49+
public const string Storage = "storage";
50+
51+
/// <summary>
52+
/// Calendar API category
53+
/// </summary>
54+
public const string Calendar = "calendar";
55+
56+
/// <summary>
57+
/// Email API category
58+
/// </summary>
59+
public const string Email = "email";
60+
61+
/// <summary>
62+
/// CRM API category
63+
/// </summary>
64+
public const string Crm = "crm";
65+
66+
/// <summary>
67+
/// Messaging API category
68+
/// </summary>
69+
public const string Messaging = "messaging";
70+
71+
/// <summary>
72+
/// ITSM API category
73+
/// </summary>
74+
public const string Itsm = "itsm";
75+
76+
/// <summary>
77+
/// Help Desk API category
78+
/// </summary>
79+
public const string HelpDesk = "helpdesk";
80+
}
81+
}
82+
}
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.Kloudless
11+
{
12+
/// <summary>
13+
/// Default values for Kloudless authentication.
14+
/// </summary>
15+
public static class KloudlessAuthenticationDefaults
16+
{
17+
/// <summary>
18+
/// Default value for <see cref="AuthenticationScheme.Name"/>.
19+
/// </summary>
20+
public const string AuthenticationScheme = "Kloudless";
21+
22+
/// <summary>
23+
/// Default value for <see cref="AuthenticationScheme.DisplayName"/>.
24+
/// </summary>
25+
public const string DisplayName = "Kloudless";
26+
27+
/// <summary>
28+
/// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>.
29+
/// </summary>
30+
public const string Issuer = "Kloudless";
31+
32+
/// <summary>
33+
/// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>.
34+
/// </summary>
35+
public const string CallbackPath = "/signin-kloudless";
36+
37+
/// <summary>
38+
/// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>.
39+
/// </summary>
40+
public const string AuthorizationEndpoint = "https://api.kloudless.com/v1/oauth";
41+
42+
/// <summary>
43+
/// Default value for <see cref="OAuthOptions.TokenEndpoint"/>.
44+
/// </summary>
45+
public const string TokenEndpoint = "https://api.kloudless.com/v1/oauth/token";
46+
47+
/// <summary>
48+
/// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>.
49+
/// </summary>
50+
public const string UserInformationEndpoint = "https://api.kloudless.com/v1/accounts/";
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.Kloudless;
9+
using JetBrains.Annotations;
10+
using Microsoft.AspNetCore.Authentication;
11+
12+
namespace Microsoft.Extensions.DependencyInjection
13+
{
14+
/// <summary>
15+
/// Extension methods to add Kloudless authentication capabilities to an HTTP application pipeline.
16+
/// </summary>
17+
public static class KloudlessAuthenticationExtensions
18+
{
19+
/// <summary>
20+
/// Adds <see cref="KloudlessAuthenticationHandler"/> to the specified
21+
/// <see cref="AuthenticationBuilder"/>, which enables Kloudless authentication capabilities.
22+
/// </summary>
23+
/// <param name="builder">The authentication builder.</param>
24+
/// <returns>A reference to this instance after the operation has completed.</returns>
25+
public static AuthenticationBuilder AddKloudless([NotNull] this AuthenticationBuilder builder)
26+
{
27+
return builder.AddKloudless(KloudlessAuthenticationDefaults.AuthenticationScheme, options => { });
28+
}
29+
30+
/// <summary>
31+
/// Adds <see cref="KloudlessAuthenticationHandler"/> to the specified
32+
/// <see cref="AuthenticationBuilder"/>, which enables Kloudless 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>A reference to this instance after the operation has completed.</returns>
37+
public static AuthenticationBuilder AddKloudless(
38+
[NotNull] this AuthenticationBuilder builder,
39+
[NotNull] Action<KloudlessAuthenticationOptions> configuration)
40+
{
41+
return builder.AddKloudless(KloudlessAuthenticationDefaults.AuthenticationScheme, configuration);
42+
}
43+
44+
/// <summary>
45+
/// Adds <see cref="KloudlessAuthenticationHandler"/> to the specified
46+
/// <see cref="AuthenticationBuilder"/>, which enables Kloudless 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 Kloudless options.</param>
51+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
52+
public static AuthenticationBuilder AddKloudless(
53+
[NotNull] this AuthenticationBuilder builder,
54+
[NotNull] string scheme,
55+
[NotNull] Action<KloudlessAuthenticationOptions> configuration)
56+
{
57+
return builder.AddKloudless(scheme, KloudlessAuthenticationDefaults.DisplayName, configuration);
58+
}
59+
60+
/// <summary>
61+
/// Adds <see cref="KloudlessAuthenticationHandler"/> to the specified
62+
/// <see cref="AuthenticationBuilder"/>, which enables Kloudless 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 Kloudless options.</param>
68+
/// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
69+
public static AuthenticationBuilder AddKloudless(
70+
[NotNull] this AuthenticationBuilder builder,
71+
[NotNull] string scheme,
72+
[CanBeNull] string caption,
73+
[NotNull] Action<KloudlessAuthenticationOptions> configuration)
74+
{
75+
return builder.AddOAuth<KloudlessAuthenticationOptions, KloudlessAuthenticationHandler>(scheme, caption, configuration);
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)