Authentication with Swift using Joss
Asked Answered
I

1

7

I created an Account (joss.model.Account) , in the configuration

allowReauthenticate=true

Almost immidiateley after account creation I call

Access mAccess = mAccount.authenticate(); // (joss.model.Access)

After that I need to use the token. I use it after 30 min and 1.5h and 24h etc. by calling mAccess.getToken() Token expatriation time is 1h. Can I suppose that re-authentication will be performed and after 1.5h as well after 24 h the token will be valid? Or I need to re-authenticate manually?

I.e. mAccess.getToken() will return invalid (expired token) after 1.5h and 24h. How to re-authenticate correctly in this case?

Intensify answered 9/5, 2016 at 20:32 Comment(0)
K
1

Just call mAccount.authenticate() once mAccess.getToken() returns invalid. Forget about time in the client app, it must be re-entrant.

Handle UI around that (re-enter username/password if needed before authenticate() method if existing credentials prove to be useless).

Kudu answered 20/5, 2016 at 23:18 Comment(2)
Do you know how can I know token expiry time?Intensify
If your API nor documentation does not provide this value, you have to use trial/error. When you get the token, save a timestamp + 3600 seconds with it. If you compare that to current time, you can expect the token to be expired after 1 hour. Or just use the token you have and in case it fails, it means it's expired.Kudu

© 2022 - 2024 — McMap. All rights reserved.