Google refreshtoken 401 错误:未经授权 - android

问题描述

我正在使用 microsoft 身份模式 oidc 客户端访问我的 android 上的 google fit 数据。登录功能按预期工作,它显示登录和同意页面并提供 accesstoken、refreshtoken 等,但是当我尝试刷新令牌时抛出 401 未经授权的错误。

它只发生一次,如果我再次尝试登录,那么刷新令牌工作正常。这是 refreshtoken 调用第一次抛出 401 错误。

谁能给点建议? 我看了 [this][1] 问题和。尝试在 refreshtoken 调用中传递 access_type=offline 但没有帮助。

登录:

 private OidcClient CreateOAuth()
        {
            OidcClient result = null;
            try
            {
              

                var discovery = new DiscoveryPolicy
                {
                    ValidateEndpoints = false,Authority = "https://accounts.google.com",};


               

                OidcClientOptions oidcClientOptions = new OidcClientOptions
                {
                    Authority = "https://accounts.google.com",ClientId = AndroidClientId
                    Scope = " https://www.googleapis.com/auth/fitness.activity.read",RedirectUri = AndroidRedirectUrl,Browser = IoCRegistry.Locate<IBrowser>(),Flow = OidcClientOptions.AuthenticationFlow.AuthorizationCode,ResponseMode = OidcClientOptions.AuthorizeResponseMode.Redirect,Policy = new Policy
                    {
                        Discovery = discovery,RequireAccessTokenHash = false 
                    }
                };

                result = new OidcClient(oidcClientOptions);
            }
            catch (Exception ex)
            {
              
            }
            return result;
        }

登录:await CreateOAuth().LoginAsync(new LoginRequest());

            var client = await CreateOAuth().RefreshTokenAsync(refreshToken,new Dictionary<string,string> { { "prompt","consent" },{ "access_type","offline" },{ "approval_prompt","force" } });

RefreshTOken(): = await CreateOAuth().RefreshTokenAsync(refreshTokennew Dictionary<string,string> { { "access_type","offline" }}); //-> 这是第一次失败(401 - 授权),然后如果您断开连接并再次登录,则此功能每次都有效。

请帮忙。 [1]:Google API refreshToken() giving error "Unauthorized client"

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)