Reputation: 13
I'm using the spring-security-facebook plugin for authentication. It works well, now I'm trying to use some functions of spring-social-facebook that needs authorization. From my controller, where can I get a valid accessToken (in order to create a FacebookTemplate object) ?
This is how I'm using the plugin:
1) I added a domain class, OAuthUser (not in the plugin but in my project)
2) I have generated a FacebookAuthDaoImpl
3) I edited the methods generated, for example in create(), I create
+ an instance of a user (main domain class SecUser) and set the profile infos
+ a new OAuthUser (where I set the uid, the accessToken, and relate it to the main user created.
UPDATE 1: I added those 3 methods in my FacebookAuthDaoImpl class:
Boolean hasValidToken(OAuthUser user){
def now= new Date()
if(now.after(user.accessTokenExpires)){
return false
} else {
return true
}
}
void updateToken(OAuthUser user, FacebookAuthToken token){
user.accessToken = token.accessToken
user.save()
}
String getAccessToken(OAuthUser user){
return user.accessToken
}
But I still have the expired AccessToken.
Upvotes: 1
Views: 709
Reputation: 35961
If you're using default DAO:
It's stored at field accessToken
of your domain object for Facebok User.
If you don't have field named accessToken
, you should add it (String accessToken
). Ideally with an additional field: Date accessTokenExpires
. And both fields will be automatically filled by the plugin.
If you've created your own DAO implementation, then:
create(FacebookAuthToken token)
pass access token as token.accessToken.accessToken
. You can store it anywhere you wishBoolean hasValidToken(F user)
, void updateToken(F user, FacebookAuthToken token)
and getAccessToken(F user)
- first should check token expiration, second update with new value (called when token is expired) and last should retourn current value.As you said, you have you own DAO implentation. How you're implemented last 3 methods?
Upvotes: 1