Skip to content

Commit 62f4482

Browse files
author
Aidan Laing
committed
Read Me Get Token
1 parent 372c1b7 commit 62f4482

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ The result of the authenticate call can be retrieved in the `onActivityResult()`
6969

7070
Calling authenticate:
7171
```kotlin
72-
client.authenticate(<OPTIONAL_REQUEST_CODE>)
72+
client?.authenticate(<OPTIONAL_REQUEST_CODE>)
7373
```
7474

7575
OnActivityResult:
@@ -87,6 +87,39 @@ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?)
8787
}
8888
```
8989

90+
### Get Token
91+
Get token will get the token from local storage.
92+
If the token is expired and the refresh token is NOT expired the token will automatically be refreshed, saved locally and returned.
93+
94+
Exceptions:
95+
1. If there is no token locally a `TokenNotFoundException` will be thrown in the onError of the TokenCallback. This means the user has not yet been authenticated so no token exists locally.
96+
2. If the token's refresh token is expired a `RefreshExpiredException` will be thrown in the onError of the TokenCallback. In this case the user will need to reauthenticate.
97+
3. If the token does not have a refresh token then a `NoRefreshTokenException` will be thrown in the onError of the TokenCallback. This means the Token data being returned does not contain the required refreshToken for this lib to work.
98+
99+
Calling getToken:
100+
```kotlin
101+
client?.getToken(object: MobileAuthenticationClient.TokenCallback {
102+
override fun onError(throwable: Throwable) {
103+
when (throwable) {
104+
is RefreshExpiredException -> {
105+
Log.e(tag, "Refresh token is expired. Please re-authenticate.")
106+
}
107+
is NoRefreshTokenException -> {
108+
Log.e(tag, "No Refresh token associated with Token")
109+
}
110+
is TokenNotFoundException -> {
111+
Log.e(tag, "No Token was found. Please authenticate first.")
112+
}
113+
}
114+
}
115+
116+
override fun onSuccess(token: Token) {
117+
Log.d(tag, "Get Token Success")
118+
}
119+
})
120+
```
121+
122+
90123

91124

92125

0 commit comments

Comments
 (0)