-
Notifications
You must be signed in to change notification settings - Fork 550
Implement VK ID OAuth2 provider #962
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
42ff0f4
provider/vk-id: Add VK ID authentication provider
hscokies a62e56e
provider/vk-id: Add VK ID tests
hscokies bcdf89c
provider/vk-id: Add provider to readme
hscokies c3427ed
provider/vk-id: Add PackageValidationBaselineVersion to csproj
hscokies 98f26d6
provider/vk-id: codestyle fixes
hscokies 9d093b3
provider/vk-id: Minor code style changes
hscokies 6176e0e
provider/vk-id: Revert README.md formatting & fix order
hscokies 5f5fa20
provider/vk-id: minor code style & xml doc fixes
hscokies 7c69c62
provider/vk-id: Add NotNull attributes & default UsePkce value
hscokies 595d9bf
provider/vk-id: Minor code refactor & logs
hscokies 366b909
provider/vk-id: Pass properties arg to HandleRequestResult.Fail; Disa…
hscokies e482f8e
provider/vk-id: fix tests for VK ID provider
hscokies 37de824
provider/vk-id: Add state parameter to token endpoint payload in tests
hscokies d5def74
provider/vk-id: Use serialized AuthenticationProperties instead of ra…
hscokies 1624279
provider/vk-id: Remove state validation from ExchangeCodeAsync
hscokies 2180680
Update Versions.props
hscokies File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/AspNet.Security.OAuth.VkId/AspNet.Security.OAuth.VkId.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFrameworks>$(DefaultNetCoreTargetFramework)</TargetFrameworks> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup> | ||
| <Description>ASP.NET Core security middleware enabling VK ID authentication.</Description> | ||
| <Authors>hscokies</Authors> | ||
| <PackageTags>aspnetcore;authentication;oauth;security;vkontakte;vkid</PackageTags> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
| <PackageReference Include="JetBrains.Annotations" PrivateAssets="All" /> | ||
| </ItemGroup> | ||
|
|
||
| <!-- TODO Enable once this provider is published to NuGet.org --> | ||
| <PropertyGroup> | ||
| <DisablePackageBaselineValidation>true</DisablePackageBaselineValidation> | ||
| </PropertyGroup> | ||
| </Project> | ||
24 changes: 24 additions & 0 deletions
24
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationConstants.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.VkId; | ||
|
|
||
| /// <summary> | ||
| /// Contains constants specific to the <see cref="VkIdAuthenticationHandler"/>. | ||
| /// </summary> | ||
| public static class VkIdAuthenticationConstants | ||
| { | ||
| public static class Claims | ||
| { | ||
| public const string Avatar = "urn:vkid:avatar:link"; | ||
| public const string IsVerified = "urn:vkid:verified"; | ||
| } | ||
|
|
||
| public static class AuthenticationProperties | ||
| { | ||
| public const string DeviceId = "DeviceId"; | ||
| } | ||
| } |
48 changes: 48 additions & 0 deletions
48
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationDefaults.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.VkId; | ||
|
|
||
| /// <summary> | ||
| /// Default values used by the VK ID authentication middleware. | ||
| /// </summary> | ||
| public static class VkIdAuthenticationDefaults | ||
| { | ||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.Name"/>. | ||
| /// </summary> | ||
| public const string AuthenticationScheme = "VK ID"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationScheme.DisplayName"/>. | ||
| /// </summary> | ||
| public const string DisplayName = "VK ID"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="AuthenticationSchemeOptions.ClaimsIssuer"/>. | ||
| /// </summary> | ||
| public const string ClaimsIssuer = "VK ID"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="RemoteAuthenticationOptions.CallbackPath"/>. | ||
| /// </summary> | ||
| public const string CallbackPath = "/signin-vkid"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.AuthorizationEndpoint"/>. | ||
| /// </summary> | ||
| public const string AuthorizationEndpoint = "https://id.vk.com/authorize"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.TokenEndpoint"/>. | ||
| /// </summary> | ||
| public const string TokenEndpoint = "https://id.vk.com/oauth2/auth"; | ||
|
|
||
| /// <summary> | ||
| /// Default value for <see cref="OAuthOptions.UserInformationEndpoint"/>. | ||
| /// </summary> | ||
| public const string UserInformationEndpoint = "https://id.vk.com/oauth2/user_info"; | ||
martincostello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
19 changes: 19 additions & 0 deletions
19
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationErrors.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| namespace AspNet.Security.OAuth.VkId; | ||
|
|
||
| public static class VkIdAuthenticationErrors | ||
martincostello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| { | ||
| public const string InvalidOAuthState = "The oauth state was missing or invalid."; | ||
| public const string CorrelationFailed = "Correlation failed."; | ||
| public const string MissingCode = "Code was not found."; | ||
| public const string MissingDeviceId = "DeviceId was not found."; | ||
| public const string MissingCodeVerifierKey = "Code verifier key was not found."; | ||
| public const string MissingAccessToken = "Failed to retrieve access_token."; | ||
| public const string MissingRefreshToken = "Failed to retrieve refresh_token."; | ||
| public const string FailedToRetrieveUserInfo = "Failed to retrieve user information."; | ||
| } | ||
74 changes: 74 additions & 0 deletions
74
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0) | ||
| * See https://github.com/aspnet-contrib/AspNet.Security.OAuth.Providers | ||
| * for more information concerning the license and the contributors participating to this project. | ||
| */ | ||
|
|
||
| using Microsoft.Extensions.DependencyInjection; | ||
|
|
||
| namespace AspNet.Security.OAuth.VkId; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods to add VK ID authentication capabilities to an HTTP application pipeline. | ||
| /// </summary> | ||
| public static class VkIdAuthenticationExtensions | ||
| { | ||
| /// <summary> | ||
| /// Adds <see cref="VkIdAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Vkontakte authentication capabilities. | ||
martincostello marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddVkId(this AuthenticationBuilder builder) | ||
| { | ||
| return builder.AddVkId(VkIdAuthenticationDefaults.AuthenticationScheme, options => { }); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="VkIdAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Vkontakte authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="configuration">The delegate used to configure the Vkontakte options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddVkId( | ||
| this AuthenticationBuilder builder, | ||
| Action<VkIdAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddVkId(VkIdAuthenticationDefaults.AuthenticationScheme, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="VkIdAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Vkontakte authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="scheme">The authentication scheme associated with this instance.</param> | ||
| /// <param name="configuration">The delegate used to configure the Vkontakte options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddVkId( | ||
| this AuthenticationBuilder builder, | ||
| string scheme, | ||
| Action<VkIdAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddVkId(scheme, VkIdAuthenticationDefaults.DisplayName, configuration); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Adds <see cref="VkIdAuthenticationHandler"/> to the specified | ||
| /// <see cref="AuthenticationBuilder"/>, which enables Vkontakte authentication capabilities. | ||
| /// </summary> | ||
| /// <param name="builder">The authentication builder.</param> | ||
| /// <param name="scheme">The authentication scheme associated with this instance.</param> | ||
| /// <param name="caption">The optional display name associated with this instance.</param> | ||
| /// <param name="configuration">The delegate used to configure the Vkontakte options.</param> | ||
| /// <returns>The <see cref="AuthenticationBuilder"/>.</returns> | ||
| public static AuthenticationBuilder AddVkId( | ||
| this AuthenticationBuilder builder, | ||
| string scheme, | ||
| [CanBeNull] string caption, | ||
| Action<VkIdAuthenticationOptions> configuration) | ||
| { | ||
| return builder.AddOAuth<VkIdAuthenticationOptions, VkIdAuthenticationHandler>(scheme, caption, configuration); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.