访问令牌无法刷新。请重新验证

时间:2019-10-13 05:30:28

标签: api oauth-2.0 onelogin

刷新访问令牌时出现此错误:无法刷新访问令牌。请重新验证

此错误先前已于2017年4月报告。OneLogin文档指出刷新令牌可以使用45天左右。我的刷新令牌大约有20个小时了。文档是否正确或刷新令牌的寿命较短?我可以很好地获取访问令牌和吊销令牌。

公共RootObject RefreshToken(HttpRequesterDM rDM)         {             RestSharp.Deserializers.JsonDeserializer deserial =新的RestSharp.Deserializers.JsonDeserializer();             var client = new RestClient(“ https://api.us.onelogin.com/auth/oauth2/token”);             var request = new RestRequest(Method.POST);             字符串clientAuth = $“ client_id:{rDM.ClientID},client_secret:{rDM.ClientSecret}”;             字符串accessToken = DSBase.AccessToken;             字符串refreshToken = DSBase.refreshToken;             request.AddHeader(“ cache-control”,“ no-cache”);             request.AddHeader(“ content-type”,“ application / json”);             request.RequestFormat = DataFormat.Json;             request.AddParameter(“ application / json”,“ {\ n \” grant_type \“:\” refresh_token \“ \ n}”,ParameterType.RequestBody);             request.AddHeader(“ authorization”,clientAuth);

        request.AddParameter("application/json", "{\n\"access_token\":\" + accessToken + \"\n}", ParameterType.RequestBody);
        request.AddParameter("application/json", "{\n\"refresh_token\":\" + refreshToken + \"\n}", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);

        RootObject returnData = deserial.Deserialize<RootObject>(response);
        if (returnData.status.message == "Access token cannot be refreshed. Please re-authenticate")
        {
            RootObject rObject = GetToken(rDM);
            return rObject;
        }
        if (returnData.data[0].access_token != null)
        {
            access = returnData.data[0].access_token; //This correctly gets the Access Token. You should return this to a class variable so that all the  other functions can access it easily and you're not constantly passing along the variable through them.

        }
        return returnData;

1 个答案:

答案 0 :(得分:0)

刷新令牌可以过期,被吊销或被拒绝。由于OneLogin是SSO,因此用户可能已注销其身份提供者,这使刷新令牌无效。您将需要设计软件来处理错误和极端情况。该错误消息很清楚,您的用户必须再次进行身份验证。除了在您发送无效/错误的刷新令牌的情况下,您的代码无需执行/更改/更正。