spring-social-github can't get user email
Asked Answered
F

0

8

I'm using spring-social/spring-social-github in order to authenticate user through GitHub in my Spring Boot web application.

In order to sign in user I have created following html form:

<form action="http://example.com/auth/github" method="POST">
 <input name="scope" value="user,gist" type="hidden">
 <button type="submit">Sign in with GitHub</button>
</form>

everything works fine except I can't get user email address.

According to GitHub documentation GitHub OAuth API user scope includes user:email and user:follow.

What can be wrong ?

UPDATED

After talking with GitHub support I have more information on this one:

The problem is that this library uses following https://api.github.com/user endpoint in order to get user profile. That endpoint returns the public email address for the user, and users don't need to specify a public email address. So, if the user doesn't have a public email address defined -- you get a null value back.

The https://api.github.com/user/emails endpoint returns the private list of email addresses and that list should always have at least one address.

if it possible to extend spring-social-github library in order to call https://api.github.com/user/emails endpoint for user email address ?

Right now I'm unable to override GitHubTemplate.initSubApis() in order to initialize my own version of UserTemplate.getUserProfile() because GitHub Template.initSubApis is a private method..

I have created issue on GitHub for spring-social-github can't get user email

Faro answered 1/5, 2015 at 11:41 Comment(9)
Did you try just user:email? What are you able to access from the API after connection is established from the profile?Springtail
the same thing.. only first name as a "null" string value and that's allFaro
Can you check through curl what scopes you have using the token, there's a code on the API page under scopes section.Springtail
X-OAuth-Scopes: user:emailFaro
The same result with: X-OAuth-Scopes: gist, userFaro
I can only get username from githubFaro
That's strange, you should contact githubs support on that matter github.com/contactSpringtail
yeah.. thanks. Submitted question to GitHub support.Faro
I got some information from GitHub support. Updated question bodyFaro

© 2022 - 2024 — McMap. All rights reserved.