Skip to content

Commit 11e302e

Browse files
authored
Merge pull request #34 from FormidableLabs/bugfix/missing-params
Bugfix/missing params
2 parents 906a4e8 + cdf9400 commit 11e302e

File tree

3 files changed

+39
-8
lines changed

3 files changed

+39
-8
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+
- **accessTokenExpirationDate** - (`string`) the token expiration date
72+
- **additionalParameters** - (`Object`) additional url parameters from the auth server
73+
- **idToken** - (`string`) the id token
74+
- **refreshToken** - (`string`) the refresh token
75+
- **tokenType** - (`string`) the token type, e.g. Bearer
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: 18 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

@@ -58,11 +59,28 @@ private WritableMap tokenResponseToMap(TokenResponse response) {
5859
Date expirationDate = new Date(response.accessTokenExpirationTime);
5960
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
6061
String expirationDateString = formatter.format(expirationDate);
62+
WritableMap additionalParametersMap = Arguments.createMap();
63+
64+
if (!response.additionalParameters.isEmpty()) {
65+
66+
Iterator<String> iterator = response.additionalParameters.keySet().iterator();
67+
68+
while(iterator.hasNext()) {
69+
String key = iterator.next();
70+
additionalParametersMap.putString(key, response.additionalParameters.get(key));
71+
}
72+
73+
map.putMap("additionalParameters", additionalParametersMap);
74+
}
6175

6276
WritableMap map = Arguments.createMap();
6377
map.putString("accessToken", response.accessToken);
6478
map.putString("accessTokenExpirationDate", expirationDateString);
79+
map.putMap("additionalParameters", additionalParametersMap);
80+
map.putString("idToken", response.idToken);
6581
map.putString("refreshToken", response.refreshToken);
82+
map.putString("tokenType", response.tokenType);
83+
6684
return map;
6785
}
6886

ios/RNAppAuth.m

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ - (dispatch_queue_t)methodQueue
5757

5858
NSDictionary *authStateDict = @{
5959
@"accessToken": authState.lastTokenResponse.accessToken,
60-
@"tokenType": authState.lastTokenResponse.tokenType,
6160
@"accessTokenExpirationDate": exporationDateString,
61+
@"additionalParameters": authState.lastTokenResponse.additionalParameters,
6262
@"idToken": authState.lastTokenResponse.idToken,
6363
@"refreshToken": authState.lastTokenResponse.refreshToken ? authState.lastTokenResponse.refreshToken : @"",
64-
@"additionalParameters": authState.lastTokenResponse.additionalParameters,
64+
@"tokenType": authState.lastTokenResponse.tokenType,
6565
};
6666
resolve(authStateDict);
6767
} else {
@@ -118,8 +118,11 @@ - (dispatch_queue_t)methodQueue
118118

119119
resolve(@{
120120
@"accessToken": response.accessToken ? response.accessToken : @"",
121-
@"refreshToken": response.refreshToken ? response.refreshToken : @"",
122121
@"accessTokenExpirationDate": exporationDateString,
122+
@"additionalParameters": response.additionalParameters,
123+
@"idToken": response.idToken ? response.idToken : @"",
124+
@"refreshToken": response.refreshToken ? response.refreshToken : @"",
125+
@"tokenType": response.tokenType ? response.tokenType : @"",
123126
});
124127
} else {
125128
reject(@"RNAppAuth Error", [error localizedDescription], error);

0 commit comments

Comments
 (0)