如何使用 Lock 在 Auth0 中获取刷新令牌并做出本机反应
how to obtain a refresh token in Auth0 using Lock and react native
在react native app中,如何获取refresh token。我在文档中看到您可以通过 REST API 中的委托端点直接调用刷新令牌端点 - 但是是否有更抽象的方法来使用 Auth0 锁定组件来完成此操作?也许某种设置是 "remember login" 并为您完成所有管道?
如果不是,那么要自己实现它,我们会在每次应用启动时调用刷新令牌服务吗?如果是这样,我们是直接进行 REST 调用还是应该通过某种 auth0 库进行调用?
是否有示例代码使用显示所需步骤的库,例如
检查现有令牌是否已过期
获取刷新令牌
将刷新令牌兑换为访问令牌
或者,这些步骤是否被库以某种方式抽象掉了?
您收到的作为用户身份验证结果的 id_token
遵循 OpenID Connect 规范,因此它将包含一个 exp
声明,您可以检查该声明以检测过期。
exp: Expiration time on or after which the ID Token MUST NOT be accepted for processing. The processing of this parameter requires that the current date/time MUST be before the expiration date/time listed in the value. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value is a JSON number representing the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date/time.
(重点是我的;来源:OpenID Connect)
如果在执行身份验证过程时包含 offline_access
范围,您应该获得与 ID 令牌一起颁发的刷新令牌。
根据 react-native-lock
documentation,您可以使用 authenticationAPI()
方法获取可用于刷新用户令牌的身份验证 API 客户端。
具体调用见react-native-auth0
documentation:
.authentication('{YOUR_CLIENT_ID}')
.refreshToken('user refresh_token')
.then(response => console.log(response))
.catch(error => console.log(error));
在react native app中,如何获取refresh token。我在文档中看到您可以通过 REST API 中的委托端点直接调用刷新令牌端点 - 但是是否有更抽象的方法来使用 Auth0 锁定组件来完成此操作?也许某种设置是 "remember login" 并为您完成所有管道?
如果不是,那么要自己实现它,我们会在每次应用启动时调用刷新令牌服务吗?如果是这样,我们是直接进行 REST 调用还是应该通过某种 auth0 库进行调用?
是否有示例代码使用显示所需步骤的库,例如
检查现有令牌是否已过期
获取刷新令牌
将刷新令牌兑换为访问令牌
或者,这些步骤是否被库以某种方式抽象掉了?
您收到的作为用户身份验证结果的 id_token
遵循 OpenID Connect 规范,因此它将包含一个 exp
声明,您可以检查该声明以检测过期。
exp: Expiration time on or after which the ID Token MUST NOT be accepted for processing. The processing of this parameter requires that the current date/time MUST be before the expiration date/time listed in the value. Implementers MAY provide for some small leeway, usually no more than a few minutes, to account for clock skew. Its value is a JSON number representing the number of seconds from 1970-01-01T0:0:0Z as measured in UTC until the date/time.
(重点是我的;来源:OpenID Connect)
如果在执行身份验证过程时包含 offline_access
范围,您应该获得与 ID 令牌一起颁发的刷新令牌。
根据 react-native-lock
documentation,您可以使用 authenticationAPI()
方法获取可用于刷新用户令牌的身份验证 API 客户端。
具体调用见react-native-auth0
documentation:
.authentication('{YOUR_CLIENT_ID}')
.refreshToken('user refresh_token')
.then(response => console.log(response))
.catch(error => console.log(error));