I have SSO integration with my Application using Google SSO Login. I was able to get information from Google UserProfile till 20th October and User was able to successfully login to application.
But after 20th October user was not able to login using SSO login because i was not getting the email information from Google. I don't know what happened suddenly from Google Oauth side that I am not receiving the data.
I have seen from Google Developer Admin console that all the API are enable including People, Google+ and I have the same client_id and Secret key in my application properties which is present in developer console. I have tried changing the scope.
Currently the scope which I had set in Application was Email scope and I was getting information from last 2 years. I changed to Profile , set the scope to profile but after that also I got only Name information not the email and other information.
<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-google</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
Code:
public class GoogleConnectionFactory extends OAuth2ConnectionFactory<Google> {
public GoogleConnectionFactory(String clientId, String clientSecret) {
super("google", new GoogleServiceProvider(clientId, clientSecret),
new GoogleAdapter());
}
@Override
protected String extractProviderUserId(AccessGrant accessGrant) {
Google api = ((GoogleServiceProvider)getServiceProvider()).getApi(accessGrant.getAccessToken());
UserProfile userProfile = getApiAdapter().fetchUserProfile(api);
return userProfile.getUsername();
}
}
public Connection<S> createConnection(AccessGrant accessGrant) {
return new OAuth2Connection<S>(getProviderId(), extractProviderUserId(accessGrant), accessGrant.getAccessToken(),
accessGrant.getRefreshToken(), accessGrant.getExpireTime(), getOAuth2ServiceProvider(), getApiAdapter());
}
public Connection getConnection(AccessGrant accessGrant, String providerId){
GoogleConnectionFactory connectionFactory = (GoogleConnectionFactory) connectionFactoryLocator.getConnectionFactory(providerId);
return connectionFactory.createConnection(accessGrant);
}
public RedirectView getAuthorizeUrl(String providerId, HttpSession session, String returnUrl) {
String state = UUID.randomUUID().toString();
session.setAttribute("STATE", state);
OAuth2Operations oauthOperations = null;
OAuth2Parameters params = new OAuth2Parameters();
if(SocialConstants.LINKEDIN_PROVIDER_ID.equals(providerId)){
LinkedInConnectionFactory connectionFactory = (LinkedInConnectionFactory) connectionFactoryLocator.getConnectionFactory(providerId);
oauthOperations = connectionFactory.getOAuthOperations();
params.setRedirectUri(returnUrl);
}else if(SocialConstants.GOOGLE_PROVIDER_ID.equals(providerId)){
GoogleConnectionFactory connectionFactory = (GoogleConnectionFactory) connectionFactoryLocator.getConnectionFactory(providerId);
//ConnectionData cd = new ConnectionData("google", null, null, null, null, "ddd", null, null, null);
//connectionFactory.createConnection(cd);
oauthOperations = connectionFactory.getOAuthOperations();
//params.setScope("profile,email");//profile
params.setScope("email");
params.put("prompt", new ArrayList<>(Arrays.asList("consent")));//profile
params.setRedirectUri(returnUrl);
}
params.setState(state);
String authorizeUrl = oauthOperations.buildAuthorizeUrl(GrantType.AUTHORIZATION_CODE, params);
return new RedirectView(authorizeUrl);
}
I should get the email from UserProfile while getting connection. I am getting UserProfile Object but not all the information.
I am getting the correct url from google to fetch the person data
The return url is also correct.