简体   繁体   English

如何在App iOS中管理令牌刷新

[英]How to make to manage token refresh in app ios

I have a web site where I have built a API Rest for IOS app. 我有一个网站,该网站为IOS应用程序构建了API Rest。 The app is composed from a Tab bar with two views the first view show the view of WELCOME or LIST OF EVENTS it depends on if user is logged or no, and the second view show the LOGINVIEW. 该应用程序由带有两个视图的选项卡栏组成,第一个视图显示“ WELCOMELIST OF EVENTS ”视图,它取决于用户是否登录,而第二个视图显示LOGINVIEW。 I have built the method on server that check if the token is valid yet in the time so that if the user has already made the login in the app, when the token will expire, I would like that the app would has to do a refresh token (by call to the server tokenIsAlive the response NO and it would make autoLogin in background) using the credential saved in the NSUserdefault in the device. 我已经在服务器上构建了一种方法,该方法可以检查令牌是否在时间上仍然有效,以便如果用户已经在应用程序中进行了登录,那么令牌何时到期,我希望该应用程序必须进行刷新令牌(通过调用服务器tokenIsAlive响应NO,它将使用设备中NSUserdefault中保存的凭据进行后台登录)。 But I would like that the refresh token would has to be hidden (background) so that the app can show the views where require the authenticated user. 但是我希望刷新令牌必须隐藏(背景),以便应用程序可以在需要经过身份验证的用户的地方显示视图。 I have used AFNetworking but how can I make to refresh token hidden? 我使用过AFNetworking,但是如何使隐藏的令牌刷新? Which way would be advised to check if the token is not expire? 建议使用哪种方式检查令牌是否未过期? Does it to do for each call (getEvent,getListEvents,updateEvent..ecc) to the server, or only into the method 它是对服务器的每次调用(getEvent,getListEvents,updateEvent..ecc)还是仅对方法的调用执行的操作

(void)applicationDidBecomeActive:(UIApplication *)application 

?

The easiest approach is to set an NSTimer to call a method that does the refreshing after a set time interval (depending on the expiry time of the token). 最简单的方法是将NSTimer设置为调用在设定的时间间隔(取决于令牌的到期时间)后进行刷新的方法。 Also, set the timer's repeat property to TRUE. 另外,将计时器的repeat属性设置为TRUE。 This way, the token remains fresh and does not expire unless the user logs out. 这样,令牌将保持最新状态,并且除非用户注销,否则令牌不会过期。 When the user logs out,make sure you invalidate the timer and stop refreshing the token. 用户注销后,请确保您使计时器无效并停止刷新令牌。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM