Skip to content

Commit 3cb48f7

Browse files
author
Kadi Kraman
committed
Enable passing in additionalParameters in iOS
1 parent 237eda0 commit 3cb48f7

File tree

5 files changed

+28
-8
lines changed

5 files changed

+28
-8
lines changed

README.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ const result = await appAuth.authorize(scopes);
5454
// returns accessToken, accessTokenExpirationDate and refreshToken
5555
```
5656

57+
## config
58+
59+
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
64+
5765
### `refresh`
5866

5967
This method will refresh the accessToken using the refreshToken. Some auth providers will also give
@@ -280,7 +288,7 @@ import AppAuth from 'react-native-app-auth';
280288
// initialise the client with your configuration
281289
const appAuth = new AppAuth({
282290
issuer: '<YOUR_ISSUER_URL>',
283-
clientId: '<YOUR_CLIENT_ID',
291+
clientId: '<YOUR_CLIENT_ID>',
284292
redirectUrl: '<YOUR_REDIRECT_URL>',
285293
});
286294

index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ export default class AppAuth {
2323
this.config.issuer,
2424
this.config.redirectUrl,
2525
this.config.clientId,
26-
scopes
26+
scopes,
27+
this.config.additionalParameters
2728
);
2829
}
2930

@@ -36,7 +37,8 @@ export default class AppAuth {
3637
this.config.redirectUrl,
3738
this.config.clientId,
3839
refreshToken,
39-
scopes
40+
scopes,
41+
this.config.additionalParameters
4042
);
4143
}
4244

index.spec.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ describe('AppAuth', () => {
1717
issuer: 'test-issuer',
1818
redirectUrl: 'test-redirectUrl',
1919
clientId: 'test-clientId',
20+
additionalParameters: { hello: 'world' },
2021
};
2122

2223
beforeAll(() => {
@@ -33,6 +34,11 @@ describe('AppAuth', () => {
3334
expect(appAuth.getConfig()).toEqual(config);
3435
});
3536

37+
it('saves the additionalParameters correctly if they are empty', () => {
38+
const appAuth = new AppAuth({ ...config, additionalParameters: undefined });
39+
expect(appAuth.getConfig()).toEqual({ ...config, additionalParameters: undefined });
40+
});
41+
3642
it('throws an error when issuer is not a string', () => {
3743
expect(() => {
3844
new AppAuth({ ...config, issuer: () => ({}) }); // eslint-disable-line no-new
@@ -81,7 +87,8 @@ describe('AppAuth', () => {
8187
config.issuer,
8288
config.redirectUrl,
8389
config.clientId,
84-
scopes
90+
scopes,
91+
config.additionalParameters
8592
);
8693
});
8794
});
@@ -124,7 +131,8 @@ describe('AppAuth', () => {
124131
config.redirectUrl,
125132
config.clientId,
126133
refreshToken,
127-
scopes
134+
scopes,
135+
config.additionalParameters
128136
);
129137
});
130138
});

ios/RNAppAuth.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ - (dispatch_queue_t)methodQueue
1818
redirectUrl: (NSString *) redirectUrl
1919
clientId: (NSString *) clientId
2020
scopes: (NSArray *) scopes
21+
additionalParameters: (NSDictionary *_Nullable) additionalParameters
2122
resolve:(RCTPromiseResolveBlock) resolve
2223
reject: (RCTPromiseRejectBlock) reject)
2324
{
@@ -35,7 +36,7 @@ - (dispatch_queue_t)methodQueue
3536
scopes:scopes
3637
redirectURL:[NSURL URLWithString:redirectUrl]
3738
responseType:OIDResponseTypeCode
38-
additionalParameters:nil];
39+
additionalParameters:additionalParameters];
3940

4041

4142
// performs authentication request
@@ -79,6 +80,7 @@ - (dispatch_queue_t)methodQueue
7980
clientId: (NSString *) clientId
8081
refreshToken: (NSString *) refreshToken
8182
scopes: (NSArray *) scopes
83+
additionalParameters: (NSDictionary *_Nullable) additionalParameters
8284
resolve:(RCTPromiseResolveBlock) resolve
8385
reject: (RCTPromiseRejectBlock) reject)
8486
{
@@ -99,7 +101,7 @@ - (dispatch_queue_t)methodQueue
99101
scopes:scopes
100102
refreshToken:refreshToken
101103
codeVerifier:nil
102-
additionalParameters:nil];
104+
additionalParameters:additionalParameters];
103105

104106
[OIDAuthorizationService performTokenRequest:tokenRefreshRequest
105107
callback:^(OIDTokenResponse *_Nullable response,

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4076,7 +4076,7 @@ preserve@^0.2.0:
40764076
version "0.2.0"
40774077
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
40784078

4079-
prettier@^1.10.2:
4079+
prettier@1.10.2:
40804080
version "1.10.2"
40814081
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.10.2.tgz#1af8356d1842276a99a5b5529c82dd9e9ad3cc93"
40824082

0 commit comments

Comments
 (0)