如何使用Android使用authrequest在LinkedIn注销?

时间:2011-04-29 11:03:24

标签: android oauth integration linkedin

我开发了一个与linkedIn集成的应用程序..! 我使用OAuth服务在linkedIn中进行SignIn身份验证以发布网络更新..但现在如何自动注销(解除身份验证)到LinkedIn?

先谢谢。

2 个答案:

答案 0 :(得分:9)

根据官方blog

  

令牌失效

现在,您可以为应用程序使OAuth令牌无效。只需将OAuth签名的GET请求发送至:

即可
  

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

200响应表示令牌已成功失效。

但按照this

  

第三方应用程序没有任何方法可以将用户注销   LinkedIn - 这是由网站控制的。使令牌失效   使用户下次尝试使用时重新授权   应用程序,但一旦他们登录到他们的浏览器LinkedIn   将保持登录状态,直到他们通过网站退出。

所以总结:截至本文撰写之日,Linked In并未对第三方应用程序提供此支持

答案 1 :(得分:0)

阅读你的问题我也试图找到解决方案,并与先生谈过。 Nabeel Siddiqui - linkedin-j API的作者

当我问是否可以使用linkedin-j api退出时,这是他的回复?

嗨Mayur 有一个方法LinkedInOAuthService#invalidateAccessToken应该使您的访问令牌无效。社区没有太多使用它,所以我不确定它是否按预期工作。如果有问题,请尝试并告诉我。 问候 Nabeel Mukhtar

所以在我的活动中,我尝试使用这种方式。

    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

        }
    }

请尝试这种方式并告诉我它是否能解决您的问题。

因为我也已经下载并看到了用于linkedin-j API的SourceCode 的 LinkedInOAuthServiceImpl.java

他们已经给出了函数,如果我们在文件中编写相同的代码,该函数也可以工作。 就是这样,

@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);
        }
    }