Skip to content
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

Implement VK ID OAuth2 provider #962

Merged
merged 16 commits into from
Nov 7, 2024

Conversation

HScokies
Copy link
Contributor

Implement VK ID OAuth2.

Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provider needs adding to README.

src/AspNet.Security.OAuth.VkId/VkIdAuthenticationErrors.cs Outdated Show resolved Hide resolved
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationScopes.cs Outdated Show resolved Hide resolved
Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I see the PR changes, but I'm on vacation until next Wednesday so my ability to properly review/merge will be sporadic until then)

README.md Outdated Show resolved Hide resolved
src/AspNet.Security.OAuth.VkId/VkIdAuthenticationScopes.cs Outdated Show resolved Hide resolved
@HScokies HScokies force-pushed the provider/vk-id branch 2 times, most recently from 1728088 to 96f572f Compare November 4, 2024 17:56
Copy link
Member

@martincostello martincostello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one minor comment regarding the tests.

Comment on lines 25 to 35
var dataProtector = (IDataProtector)DataProtectionProvider.Create("test");
var fakeDataProtector = Substitute.For<IDataProtector>();

fakeDataProtector.Protect(Arg.Any<byte[]>())
.Returns(x => dataProtector.Protect(x.Arg<byte[]>()));
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => !x.SequenceEqual(Array.Empty<byte>())))
.Returns(x => dataProtector.Unprotect(x.Arg<byte[]>()));

// Use fake DP with empty AuthenticationProperties for ExchangeCodeAsync state validation
fakeDataProtector.Unprotect(Arg.Is<byte[]>(x => x.SequenceEqual(Array.Empty<byte>())))
.Returns([1, 0, 0, 0, 0, 0, 0, 0]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you make this use a slightly more realistic value that matches a non-empty scope value in the payload?

Copy link
Member

@kevinchalet kevinchalet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your PR!

}

// OAuth2 10.12 CSRF
if (ValidateCorrelationId(properties) is false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not technically wrong, but !ValidateCorrelationId(properties) would be easier to read (and consistent with the other providers).

var payload = JsonDocument.Parse(await response.Content.ReadAsStringAsync(Context.RequestAborted));

// Code exchange response should always contain state parameter.
if (!payload.RootElement.TryGetProperty("state", out var state) ||
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state in token responses is not really a standard thing and it's not clear what security benefits validating the state here provides. I'd just remove that part to simplify things.

[NotNull] AuthenticationProperties properties,
[NotNull] string redirectUri)
{
var parameter = Options.Scope;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these temp variables aren't very useful: feel free to remove them and do the formatting directly in the dictionary initializer to save a few lines.

@kevinchalet
Copy link
Member

(I find it funny that VK claims they are implementing "OAuth 2.1" - that hasn't been officially adopted yet - when all they're doing is implementing yet another non-standard version of OAuth with non-standard concepts like HTTP 200 errors and device_id 😄)

@HScokies
Copy link
Contributor Author

HScokies commented Nov 5, 2024

yea, VK is a funny company...
image

Copy link
Member

@kevinchalet kevinchalet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks a lot for your contribution! 👍🏻

I'll let @martincostello merge it in case he'd have additional feedback 😃

@martincostello martincostello added this to the 8.3.0 milestone Nov 7, 2024
@martincostello
Copy link
Member

Before merging this, can you confirm you've tested the provider against the production VK ID service and that you were able to successfully authenticate?

@martincostello
Copy link
Member

Oh, and could you update this to 3 and 0 please?

<MinorVersion>2</MinorVersion>
<PatchVersion>1</PatchVersion>

@HScokies
Copy link
Contributor Author

HScokies commented Nov 7, 2024

Before merging this, can you confirm you've tested the provider against the production VK ID service and that you were able to successfully authenticate?

Everything seems to work fine, yes
image
image

@martincostello martincostello merged commit 6c65350 into aspnet-contrib:dev Nov 7, 2024
8 checks passed
@martincostello
Copy link
Member

Thanks again for your contribution - the new provider 📦 is now available from NuGet.org: https://www.nuget.org/packages/AspNet.Security.OAuth.VkId/8.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants