fix(vk): tolerate accounts without email (#338)#641
Open
yabanci wants to merge 1 commit into
Open
Conversation
VK token endpoint omits the 'email' field when the user has no email in their profile (VK has allowed this since ~2018). Treating it as a hard requirement broke the entire login flow for those users. Make email optional: if the token response includes it, populate the session; otherwise leave Session.email empty and let the consumer handle a goth.User without an email — same contract as providers like Twitter where email is opt-in.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Closes #338.
VK's OAuth2 token endpoint omits the top-level
emailfield when the user has no email in their VK profile (VK has allowed registration without email since ~2018). The current code treats this as a fatal error:…which means accounts without an email can't complete OAuth at all.
Change
Make
emailoptional inproviders/vk/session.go:Session.emailis populated and propagated togoth.User.Email.goth.User.Emailis empty, matching the contract already used by providers like Twitter where email is opt-in.Backward compatibility
The original issue author (@nikita-vanyasin) wondered whether fixing this in-place would break existing users. In practice it cannot: the only callers affected are those that were already getting
"Cannot fetch user email"and thus already broken. Callers that received an email continue to receive it.If a downstream caller really needs to enforce an email, they can already do so by checking
user.Email == ""aftergothic.CompleteUserAuth— which is the standard pattern for optional-email providers.Tests
Added
providers/vk/authorize_internal_test.gowith two subtests usinghttptest.Serverto mock the token endpoint:TestAuthorize_PopulatesEmailWhenPresent— happy path, regression-guards existing behaviour.TestAuthorize_NoErrorWhenEmailMissing— fails on master, passes with this fix.Verified locally: the new regression test fails when the patch is reverted and passes with it applied. Full
go test ./...is green;go vet ./...is clean.