【问题标题】:how to sign out in LinkedIn using authrequest using android?如何使用android使用authrequest在LinkedIn中注销?
【发布时间】:2011-08-15 10:17:57
【问题描述】:

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

谢谢你的建议。

【问题讨论】:

标签: android oauth integration linkedin


【解决方案1】:

根据官方blog

令牌失效

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

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

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

但是根据this

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

因此,总而言之:截至撰写本文之日,Linked In 不向 3rd 方应用程序提供这种支持

【讨论】:

  • 我对ans完全满意。
【解决方案2】:

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

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

嗨,Mayur 有一种方法 LinkedInOAuthService#invalidateAccessToken 应该使您的访问令牌无效。它没有被社区使用太多,所以我不确定它是否按预期工作。尝试一下,如果有问题,请告诉我。 问候 纳比尔穆赫塔尔

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

    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 的源代码和 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);
        }
    }

【讨论】:

  • 不..!!它不适用于 invalidateAccessToken() 方法..用户在应用它后仍保持登录状态..
  • 好的..实际上我没有足够的时间来测试这个..会做更多的工作,如果我成功了会告诉你。
猜你喜欢
  • 2012-08-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-01-08
  • 1970-01-01
  • 2011-07-05
  • 1970-01-01
  • 2012-12-05
相关资源
最近更新 更多