开发者

how to sign out in LinkedIn using authrequest using android?

i dev开发者_开发问答eloped one app integrated with linkedIn..! i do SignIn authentication in linkedIn using OAuth Service to post the Network Update..but now how to sign out (de-authenticate) to the LinkedIn automatically?

Thanks in adv..


As per the official blog

Token Invalidation

Now you can invalidate an OAuth token for your application. Just send an OAuth signed GET request to:

https://api.linkedin.com/uas/oauth/invalidateToken

A 200 response indicates that the token was successfully invalidated.

However as per this :

Third party applications do not have any way to log a user out from LinkedIn - this is controlled by the website. Invalidating the token makes the user re-authorize the next time they try to use the application, but once they have logged into LinkedIn their browser will remain logged in until they log out via the website.

So In conclusion : as of this date of writing, Linked In does not give this support to 3rd Party Applications


Reading your question i have also tried to find solution and also talked to Mr. Nabeel Siddiqui - Author of linkedin-j API

and this was his reply when i asked if it's possible to sign out using linkedin-j api?

Hi Mayur There is a method LinkedInOAuthService#invalidateAccessToken that is supposed to invalidate your access token. Its not used much by the community so I am not sure if it works as expected or not. Do try it and let me know if there are problems. Regards Nabeel Mukhtar

so in my activity i tried it using this way.

    final LinkedInOAuthService oAuthService = LinkedInOAuthServiceFactory.getInstance().createLinkedInOAuthService(consumerKey, consumerSecret);
    final LinkedInApiClientFactory factory = LinkedInApiClientFactory.newInstance(consumerKey, consumerSecret);
    LinkedInRequestToken liToken;
    LinkedInApiClient client;
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        liToken = oAuthService.getOAuthRequestToken(CALLBACKURL);
        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(liToken.getAuthorizationUrl()));
        startActivity(i);
    }
    @Override
    protected void onNewIntent(Intent intent) 
    {
        super.onNewIntent(intent);
        Uri uri = intent.getData();

        if (uri != null && uri.toString().startsWith(CALLBACKURL)) 
        {
            String verifier = intent.getData().getQueryParameter("oauth_verifier");

            LinkedInAccessToken accessToken = oAuthService.getOAuthAccessToken(liToken, verifier);
            client = factory.createLinkedInApiClient(accessToken);
            Connections con = client.getConnectionsForCurrentUser();

            //AFTER FETCHING THE DATA I HAVE DONE

             oAuthService.invalidateAccessToken(accessToken);
           //this is for sign out

        }
    }

Please, Try this way once and tell me if it solves your problem.

cause I have also donwloaded and seen the SourceCode for linkedin-j API and in LinkedInOAuthServiceImpl.java

they have given the function and that function also works if we write the same code in our file. that is,

@Override
    public void invalidateAccessToken(LinkedInAccessToken accessToken) {
        if (accessToken == null) {
            throw new IllegalArgumentException("access token cannot be null.");
        }
        try {
            URL               url     = new URL(LinkedInApiUrls.LINKED_IN_OAUTH_INVALIDATE_TOKEN_URL);
            HttpURLConnection request = (HttpURLConnection) url.openConnection();

            final OAuthConsumer consumer = getOAuthConsumer();
            consumer.setTokenWithSecret(accessToken.getToken(), accessToken.getTokenSecret());
            consumer.sign(request);
            request.connect();

            if (request.getResponseCode() != HttpURLConnection.HTTP_OK) {
                throw new LinkedInOAuthServiceException(convertStreamToString(request.getErrorStream()));
            }
        } catch (Exception e) {
            throw new LinkedInOAuthServiceException(e);
        }
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜