0

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

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

有人可以请教吗?我查看了 [this][1] 问题和。试图传递access_type=offlinerefreshtoken 调用但它没有帮助。

登录:

 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() 给出错误“未经授权的客户端”

4

0 回答 0