darc
darc

Reputation: 41

How to get and reuse access token in social auth android?

I am using socialauth android for my app. My requirement is to reuse the access token keys and secret previously stored during the authorisation. I am unable to do it in any possible way, even I googled a lot but could not find any way resusing the access tokens for Facebook, twitter, g+ etc. to avoid reauthorisation and reauthentication for next time.

I am getting the token as follows

String token=adapter.getCurrentProvider().getAccessGrant().getKey()

Storing this token in database and I want to use nexr time when user tries to login agsin to avoid the process of re authentication and instead directly user must be able to use this token to perform updatestatus and other functions.

How can I do this?

Upvotes: 2

Views: 1289

Answers (1)

Tarun Nagpal
Tarun Nagpal

Reputation: 964

You can try the following

 val socialAuthManager = new SocialAuthManager    
 socialAuthManager.setSocialAuthConfig(socialAuthConfig)    
 val providerId = "linkedin"    
 val linkedinAccessToken = YOUR_TOKEN
 val accessGrant = new AccessGrant();
 accessGrant.setKey(linkedinAccessToken);
 accessGrant.setProviderId(providerId);

 AuthProvider provider = socialAuthManager.connect(accessGrant);

 Profile profile = provider.getUserProfile();

Upvotes: 1

Related Questions