Skip to content

Commit f6bc509

Browse files
author
Kadi Kraman
committed
Add the missing parameters to token response on Android
1 parent 906a4e8 commit f6bc509

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,26 @@ const result = await appAuth.authorize(scopes);
5454
// returns accessToken, accessTokenExpirationDate and refreshToken
5555
```
5656

57-
#### config
57+
#### `config`
5858

5959
This is your configuration object for the client
60-
- **issuer**: (`string`) *REQUIRED* the url of the auth server
61-
- **clientId**: (`string`) *REQUIRED* your client id on the auth server
62-
- **redirectUrl**: (`string`) *REQUIRED* the url that links back to your app with the auth code
63-
- **additionalParameters**: (`object` | `null`) additional parameters that will be passed in the authorization request.
60+
- **issuer** - (`string`) *REQUIRED* the url of the auth server
61+
- **clientId** - (`string`) *REQUIRED* your client id on the auth server
62+
- **redirectUrl** - (`string`) *REQUIRED* the url that links back to your app with the auth code
63+
- **additionalParameters** - (`object` | `null`) additional parameters that will be passed in the authorization request.
6464
Must be string values! E.g. setting `additionalParameters: { hello: 'world', foo: 'bar' }` would add
6565
`hello=world&foo=bar` to the authorization request.
6666

67+
### `result`
68+
69+
This is the result from the auth server
70+
- **accessToken** - (`string`) the access token
71+
- **tokenType** - (`string`) the token type, e.g. Bearer
72+
- **accessTokenExpirationDate** - (`string`) the token expiration date
73+
- **refreshToken** - (`string`) the refresh token
74+
- **idToken** - (`string`) the id token
75+
- **additionalParameters** - (`Object`) additional url parameters from the auth server
76+
6777
### `refresh`
6878

6979
This method will refresh the accessToken using the refreshToken. Some auth providers will also give

android/src/main/java/com/reactlibrary/RNAppAuthModule.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import java.text.SimpleDateFormat;
3030
import java.util.Date;
3131
import java.util.HashMap;
32+
import java.util.Iterator;
3233

3334
public class RNAppAuthModule extends ReactContextBaseJavaModule implements ActivityEventListener {
3435

@@ -61,8 +62,29 @@ private WritableMap tokenResponseToMap(TokenResponse response) {
6162

6263
WritableMap map = Arguments.createMap();
6364
map.putString("accessToken", response.accessToken);
65+
map.putString("tokenType", response.tokenType);
6466
map.putString("accessTokenExpirationDate", expirationDateString);
6567
map.putString("refreshToken", response.refreshToken);
68+
map.putString("idToken", response.idToken);
69+
70+
WritableMap additionalParametersMap = Arguments.createMap();
71+
72+
if (!response.additionalParameters.isEmpty()) {
73+
74+
Iterator<String> iterator = response.additionalParameters.keySet().iterator();
75+
76+
while(iterator.hasNext()) {
77+
String key = iterator.next();
78+
additionalParametersMap.putString(key, response.additionalParameters.get(key));
79+
}
80+
81+
map.putMap("additionalParameters", additionalParametersMap);
82+
}
83+
84+
map.putMap("additionalParameters", additionalParametersMap);
85+
86+
System.out.println(map);
87+
6688
return map;
6789
}
6890

0 commit comments

Comments
 (0)