-
Notifications
You must be signed in to change notification settings - Fork 541
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
Conversation
There was a problem hiding this 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.
There was a problem hiding this 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)
d2d0c66
to
5f5fa20
Compare
…bled InvertIf for ExchangeCodeAsync
1728088
to
96f572f
Compare
96f572f
to
e482f8e
Compare
There was a problem hiding this 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.
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]); |
There was a problem hiding this comment.
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?
There was a problem hiding this 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) |
There was a problem hiding this comment.
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) || |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
(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 |
There was a problem hiding this 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 😃
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? |
Oh, and could you update this to AspNet.Security.OAuth.Providers/eng/Versions.props Lines 5 to 6 in 8bff342
|
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 |
Implement VK ID OAuth2.