Comments (3)
Hi Jorge,
In the end I modified IdentifyProvider.authenticate() and made it backwards compatible. I followed the same example in the OAuth1 redirect by putting the user in the cache then redirecting to another action if one is defined in config and if necessary (e.g. email is not defined), with the cache key and return URL as parameters. The external action retrieves and updates the cached user as necessary and then redirects back to the authenticated method. On re-entry to the authentication method the cached user is checked for existence, then the cache is cleared and the updated cached user is set to be the one that will be saved. Is this a reasonable solution? Tempted to put the original URL in the cache to avoid any reliance on the external action having to preserve it.
As a general point, I'm guessing that for a clustered environment a clustered cache like memcached is required to ensure the cached SocialUser instance is accessible from all machines. This isn't mentioned in the documentation and only by looking at the code dependence on the cache would this be obvious. yes?
protected IdentityProvider(ProviderType type, AuthenticationMethod authMethod) {
this.type = type;
this.authMethod = authMethod;
this.action = Play.configuration.getProperty(getPropertiesKey(this.type) + "action");
}
public SocialUser authenticate() {
SocialUser user = null;
final String key = (this.action != null) ? new StringBuilder(SECURESOCIAL).append("ext.").append(Scope.Session.current().getId()).toString() : null;
SocialUser externalUser = (key != null) ? (SocialUser) Cache.get(key) : null;
if (externalUser == null) {
// authenticate against the 3rd party service (facebook, twitter, etc)
Map<String, Object> authContext = new HashMap<String, Object>();
user = doAuth(authContext);
// if user authenticated correctly, retrieve some profile information
fillProfile(user, authContext);
if (this.action != null && user.email == null) {
// Check if there is an existing user and if it has the email set.
SocialUser existingUser = UserService.find(user.id);
if (existingUser == null || existingUser.email == null) {
Cache.safeSet(key, user, "10min");
Flash.current().keep(SecureSocial.ORIGINAL_URL);
Map<String, Object> args = new HashMap<String, Object>();
args.put("returnURL", Request.current().getBase() + Request.current().path);
args.put("key", key);
throw new Redirect(Router.getFullUrl(this.action, args));
}
user.email = existingUser.email;
}
} else {
Cache.delete(key);
user = externalUser;
}
// save the user
user.lastAccess = new Date();
UserService.save(user);
// we're done.
return user;
}
cheers,
Chris
from securesocial.
Hi Chris,
I completely forgot to reply this. I'm sorry. That approach works, another thing you could have done is check if the user has an email within your application flow (after authentication) using a @before interceptor and if missing redirect the user to a page where he can complete his profile. After that he would be redirected again to the original destination page.
And you're right about the cache. In a clustered environment you'd need something like memcached.
Jorge
from securesocial.
@tazmaniax I'm closing this, hope my comments above helped.
from securesocial.
Related Issues (20)
- Build breaks after new release. HOT 3
- Security: password reset email host injection HOT 2
- v3.0-M7 play2.5 HOT 4
- Facebook oauth token format change causes error (suspected) HOT 3
- Getting weird issue with email sending
- Inconsistent error from Facebook Sign-in
- Ready-made Backend
- compatible HOT 2
- Control the number of rest API calls with securesocial HOT 1
- Support Play 2.6 HOT 2
- scala 2.12 HOT 1
- After hitting the /logout api, Session is not getting cleared it is only redirecting to login_page. And i am able to login again with the same token id HOT 1
- Add cookie SameSite HOT 1
- Can't use with Scala 2.12 HOT 4
- Ambiguous implicit values HOT 1
- Action Not Found For request 'GET /authenticate/github? HOT 1
- Documentation has not been update for play 2.6
- push secure social jar with support for play 2.6 to maven
- NoSuchFieldError: state (facebook provider error) HOT 1
- Looking for a maintainer?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from securesocial.