使用刷新令牌获取访问令牌 [英] Get Access Token using Refresh Token

查看:186
本文介绍了使用刷新令牌获取访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个控制台应用程序,我想在同一个应用程序中使用刷新令牌创建一个新的访问令牌。

I am creating a console application and i want to create a new access token using refresh token in the same application.

是否可以这样做?如果是,那么我该怎么做呢。请分享任何与之相关的参考或示例。

Is it possible to do this?, if yes then how can i do this. please share any reference or example related of it.

我正在使用下面提到的代码从刷新令牌重新生成访问令牌,但是我的代码突然停在突出显示的部分。它甚至没有抛出任何异常。您能告诉我们原因吗?

i am using below mentioned code regenerating access token from refresh token, However my code stops suddenly at the highlighted section. It doesn't even throw any exception. Could you please let us know what the reason maybe?

private static async Task< Authentication> AuthorizeDesktopMobileAuthCodeGrant()

        {

            var auth = new OAuthDesktopMobileAuthCodeGrant(ClientId);

           试试
            {

               
等待AuthorizeWithRefreshTokenAsync(auth,refreshToken);

            }
            catch(例外){}

           返回身份验证;

        }


        private static Task< OAuthTokens> AuthorizeWithRefreshTokenAsync(OAuthDesktopMobileAuthCodeGrant auth,string refreshToken)

        {

            return auth.RequestAccessAndRefreshTokensAsync(refreshToken);

        }

private static async Task<Authentication> AuthorizeDesktopMobileAuthCodeGrant()
        {
            var auth = new OAuthDesktopMobileAuthCodeGrant(ClientId);
            try
            {
                await AuthorizeWithRefreshTokenAsync(auth, refreshToken);
            }
            catch (Exception) { }
            return auth;
        }

        private static Task<OAuthTokens> AuthorizeWithRefreshTokenAsync(OAuthDesktopMobileAuthCodeGrant auth, string refreshToken)
        {
            return auth.RequestAccessAndRefreshTokensAsync(refreshToken);
        }

推荐答案

请参阅
GitHub
如果您有任何后续问题,请与我们联系。这可能有助于下载完整的示例(也可以在

MSDN
)并逐步完成。

Please refer to the example on GitHub and let me know if you have any follow up questions. It might help to download the full example (also available on MSDN) and step through it.

我希望这有帮助!


这篇关于使用刷新令牌获取访问令牌的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆