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

发布于 2024-11-04 09:00:34 字数 120 浏览 3 评论 0原文

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

感谢在广告..

i developed 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..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巡山小妖精 2024-11-11 09:00:34

根据官方博客

令牌失效

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

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

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

但是,根据

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

总之:截至撰写本文之日,Linked In 不向第三方应用程序提供此支持

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

若言繁花未落 2024-11-11 09:00:34

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

当我询问是否可以使用 linkedin-j api 注销时,这是他的回复。

嗨,马尤尔
有一个方法 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 的源代码以及
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);
        }
    }

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);
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文