Skip to content
This repository was archived by the owner on Mar 18, 2025. It is now read-only.

Commit 5930f6d

Browse files
authored
Feature/cookieless ios session (#4)
* add prop to cryptrconfig to handle ios ephemeral session * change key name and adapt base code * startSecuredView with no_popup_no_cookie param * hotfix android update for no_popup_no_cookie
1 parent 7a96ed4 commit 5930f6d

File tree

11 files changed

+117
-3
lines changed

11 files changed

+117
-3
lines changed

android/src/main/java/com/reactnativecryptr/CryptrModule.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ class CryptrModule(reactContext: ReactApplicationContext) : ReactContextBaseJava
118118
@ReactMethod(isBlockingSynchronousMethod = true)
119119
fun startSecuredView(
120120
uri: String,
121+
_no_popup_no_cookie: Boolean,
121122
successCallback: Callback,
122123
errorCallback: Callback,
123124
) {

ios/Cryptr.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ - (void)openInSafari:(NSURL *)URL {
108108
}
109109

110110
RCT_EXPORT_METHOD(startSecuredView:(NSURL *)url
111+
prefersEphemeralWebBrowserSession:(BOOL)prefersEphemeralWebBrowserSession
111112
successCallback:(RCTResponseSenderBlock)successCallback
112113
errorCallback:(RCTResponseSenderBlock)errorCallback)
113114
{
@@ -142,9 +143,9 @@ - (void)openInSafari:(NSURL *)URL {
142143
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 130000
143144
if (@available(iOS 13.0, *)) {
144145
session.presentationContextProvider = self;
145-
// if ([urlStr rangeOfString:@"slo-after-revoke-token"].location == NSNotFound) {
146-
// session.prefersEphemeralWebBrowserSession = true;
147-
// }
146+
if (prefersEphemeralWebBrowserSession) {
147+
session.prefersEphemeralWebBrowserSession = true;
148+
}
148149
}
149150
#endif
150151

src/__tests__/components/CryptrSsoGatewayButton.test.tsx

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,56 @@ describe('CryptrSsoGatewayButton', () => {
168168
expect.stringContaining(
169169
'https://auth.cryptr.eu/t/shark_academy/?client_id=123'
170170
),
171+
false,
171172
expect.anything(),
172173
expect.anything()
173174
);
174175
expect(startSecuredViewFn).toHaveBeenCalledWith(
175176
expect.not.stringContaining('idp_id='),
177+
false,
176178
expect.anything(),
177179
expect.anything()
178180
);
179181

180182
expect(startSecuredViewFn).toHaveBeenCalledWith(
181183
expect.not.stringContaining('idp_ids%5B%5D='),
184+
false,
185+
expect.anything(),
186+
expect.anything()
187+
);
188+
189+
startSecuredViewFn.mockRestore();
190+
});
191+
192+
it('should start standard gateway process without no_popup_no_cookie is true on press action', () => {
193+
const { getByText } = render(
194+
<CryptrProvider {...config} no_popup_no_cookie={true}>
195+
<CryptrSsoGatewayButton>
196+
<Text>Custom idp content</Text>
197+
</CryptrSsoGatewayButton>
198+
</CryptrProvider>
199+
);
200+
const item = getByText('Custom idp content');
201+
const startSecuredViewFn = jest.spyOn(Cryptr, 'startSecuredView');
202+
fireEvent.press(item);
203+
expect(startSecuredViewFn).toHaveBeenCalledWith(
204+
expect.stringContaining(
205+
'https://auth.cryptr.eu/t/shark_academy/?client_id=123'
206+
),
207+
true,
208+
expect.anything(),
209+
expect.anything()
210+
);
211+
expect(startSecuredViewFn).toHaveBeenCalledWith(
212+
expect.not.stringContaining('idp_id='),
213+
true,
214+
expect.anything(),
215+
expect.anything()
216+
);
217+
218+
expect(startSecuredViewFn).toHaveBeenCalledWith(
219+
expect.not.stringContaining('idp_ids%5B%5D='),
220+
true,
182221
expect.anything(),
183222
expect.anything()
184223
);
@@ -199,17 +238,20 @@ describe('CryptrSsoGatewayButton', () => {
199238
fireEvent.press(item);
200239
expect(startSecuredViewFn).toHaveBeenCalledWith(
201240
expect.stringContaining('https://auth.cryptr.eu/?client_id'),
241+
false,
202242
expect.anything(),
203243
expect.anything()
204244
);
205245
expect(startSecuredViewFn).toHaveBeenCalledWith(
206246
expect.not.stringContaining('idp_id='),
247+
false,
207248
expect.anything(),
208249
expect.anything()
209250
);
210251

211252
expect(startSecuredViewFn).toHaveBeenCalledWith(
212253
expect.not.stringContaining('idp_ids%5B%5D='),
254+
false,
213255
expect.anything(),
214256
expect.anything()
215257
);
@@ -230,6 +272,7 @@ describe('CryptrSsoGatewayButton', () => {
230272
fireEvent.press(item);
231273
expect(startSecuredViewFn).toHaveBeenCalledWith(
232274
expect.stringContaining('idp_id=app_sso_idp_id'),
275+
false,
233276
expect.anything(),
234277
expect.anything()
235278
);
@@ -249,11 +292,13 @@ describe('CryptrSsoGatewayButton', () => {
249292
fireEvent.press(item);
250293
expect(startSecuredViewFn).toHaveBeenCalledWith(
251294
expect.stringContaining('idp_ids%5B%5D=app_sso_idp_id'),
295+
false,
252296
expect.anything(),
253297
expect.anything()
254298
);
255299
expect(startSecuredViewFn).toHaveBeenCalledWith(
256300
expect.stringContaining('idp_ids%5B%5D=another_idp_id'),
301+
false,
257302
expect.anything(),
258303
expect.anything()
259304
);

src/__tests__/components/CryptrSsoSignInButton.test.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ describe('CryptrSsoSignInButton', () => {
101101
expect.stringMatching(
102102
'https://auth.cryptr.eu/enterprise/app_sso_idp_id/login'
103103
),
104+
false,
105+
expect.anything(),
106+
expect.anything()
107+
);
108+
});
109+
110+
it('should start sso process when no_popup_no_cookie is true on press action', () => {
111+
const { getByText } = render(
112+
<CryptrProvider {...config} no_popup_no_cookie={true}>
113+
<CryptrSsoSignInButton idpId="app_sso_idp_id">
114+
<Text>Custom idp content</Text>
115+
</CryptrSsoSignInButton>
116+
</CryptrProvider>
117+
);
118+
const item = getByText('Custom idp content');
119+
const startSecuredViewFn = jest.spyOn(Cryptr, 'startSecuredView');
120+
fireEvent.press(item);
121+
expect(startSecuredViewFn).toHaveBeenCalledWith(
122+
expect.stringMatching(
123+
'https://auth.cryptr.eu/enterprise/app_sso_idp_id/login'
124+
),
125+
true,
104126
expect.anything(),
105127
expect.anything()
106128
);

src/__tests__/utils/apiHelpers.test.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ describe('apiHelpers#tokenUrl/3', () => {
7474
audience: 'cryptr://app',
7575
default_redirect_uri: 'cryptr://app',
7676
dedicated_server: false,
77+
no_popup_no_cookie: false,
7778
};
7879
const authorization = { authorization_id: 'azerty' };
7980

@@ -125,6 +126,7 @@ describe('apiHelpers#ssoSignUrl/3', () => {
125126
audience: 'cryptr://app',
126127
default_redirect_uri: 'cryptr://app',
127128
dedicated_server: false,
129+
no_popup_no_cookie: false,
128130
};
129131
const idpId = 'shark_academy_po54ze';
130132
const transaction = new Transaction(config.default_redirect_uri, Sign.SSO);
@@ -146,6 +148,7 @@ describe('apiHelpers#revokeTokenUrl/1', () => {
146148
audience: 'cryptr://app',
147149
default_redirect_uri: 'cryptr://app',
148150
dedicated_server: false,
151+
no_popup_no_cookie: false,
149152
};
150153

151154
it('should return revoke token url if sample transaction and sample refresh', () => {
@@ -173,6 +176,7 @@ describe('apiHelpers#sloAfterRevokeTokenUrl/2', () => {
173176
audience: 'cryptr://app',
174177
default_redirect_uri: 'cryptr://app',
175178
dedicated_server: false,
179+
no_popup_no_cookie: false,
176180
};
177181
const sloCode = 'remove_me';
178182

@@ -193,6 +197,7 @@ describe('apiHelpers#refreshTokenUrl/2', () => {
193197
audience: 'cryptr://app',
194198
default_redirect_uri: 'cryptr://app',
195199
dedicated_server: false,
200+
no_popup_no_cookie: false,
196201
};
197202
const refreshTransaction = new Transaction(
198203
config.default_redirect_uri,
@@ -228,6 +233,7 @@ describe('apiHelpers#ssoGatewayUrl', () => {
228233
audience: 'cryptr://app',
229234
default_redirect_uri: 'cryptr://app',
230235
dedicated_server: false,
236+
no_popup_no_cookie: false,
231237
};
232238

233239
const transaction = new Transaction(config.default_redirect_uri, Sign.SSO);

src/__tests__/utils/helpers.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ describe('helpers#refreshBody/3', () => {
1818
audience: 'cryptr://app',
1919
default_redirect_uri: 'cryptr://app',
2020
dedicated_server: false,
21+
no_popup_no_cookie: false,
2122
};
2223
const refreshToken = 'shark_academy_po54ze';
2324
const refreshTransaction = new Transaction(
@@ -41,6 +42,7 @@ describe('helpers#tokensBody/3', () => {
4142
audience: 'cryptr://app',
4243
default_redirect_uri: 'cryptr://app',
4344
dedicated_server: false,
45+
no_popup_no_cookie: false,
4446
};
4547
const params = { authorization_id: 'auth_id' };
4648
const transaction = new Transaction(config.default_redirect_uri, Sign.SSO);
@@ -106,6 +108,7 @@ describe('helpers#prepareConfig/1', () => {
106108
cryptr_base_url: 'https://auth.cryptr.eu',
107109
default_locale: 'en',
108110
dedicated_server: false,
111+
no_popup_no_cookie: false,
109112
});
110113
});
111114

@@ -126,6 +129,7 @@ describe('helpers#prepareConfig/1', () => {
126129
cryptr_base_url: 'https://shark-academy.authent.me',
127130
default_locale: 'en',
128131
dedicated_server: false,
132+
no_popup_no_cookie: false,
129133
});
130134
});
131135

@@ -146,6 +150,7 @@ describe('helpers#prepareConfig/1', () => {
146150
cryptr_base_url: 'https://auth.cryptr.eu',
147151
default_locale: 'en',
148152
dedicated_server: false,
153+
no_popup_no_cookie: false,
149154
});
150155
});
151156

@@ -166,6 +171,7 @@ describe('helpers#prepareConfig/1', () => {
166171
cryptr_base_url: 'https://auth.cryptr.us',
167172
default_locale: 'en',
168173
dedicated_server: false,
174+
no_popup_no_cookie: false,
169175
});
170176
});
171177

@@ -187,6 +193,7 @@ describe('helpers#prepareConfig/1', () => {
187193
cryptr_base_url: 'https://shark-academy.authent.me',
188194
default_locale: 'en',
189195
dedicated_server: false,
196+
no_popup_no_cookie: false,
190197
});
191198
});
192199

@@ -207,6 +214,7 @@ describe('helpers#prepareConfig/1', () => {
207214
cryptr_base_url: 'https://auth.cryptr.eu',
208215
default_locale: 'fr',
209216
dedicated_server: false,
217+
no_popup_no_cookie: false,
210218
});
211219
});
212220

@@ -228,6 +236,29 @@ describe('helpers#prepareConfig/1', () => {
228236
cryptr_base_url: 'https://auth.cryptr.eu',
229237
default_locale: 'fr',
230238
dedicated_server: true,
239+
no_popup_no_cookie: false,
240+
});
241+
});
242+
243+
it('should returns chosen no_popup_no_cookie config if provided', () => {
244+
expect(
245+
prepareConfig({
246+
tenant_domain: 'shark_academy',
247+
client_id: 'client_id',
248+
audience: 'cryptr://audience',
249+
default_redirect_uri: 'cryptr://defaultRedirectUri',
250+
default_locale: 'fr',
251+
no_popup_no_cookie: true,
252+
})
253+
).toEqual({
254+
tenant_domain: 'shark_academy',
255+
client_id: 'client_id',
256+
audience: 'cryptr://audience',
257+
default_redirect_uri: 'cryptr://defaultRedirectUri',
258+
cryptr_base_url: 'https://auth.cryptr.eu',
259+
default_locale: 'fr',
260+
dedicated_server: false,
261+
no_popup_no_cookie: true,
231262
});
232263
});
233264
});

src/__tests__/utils/jwt.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ let config: PreparedCryptrConfig = {
1919
client_id: 'e2629eb9-3f56-4397-b19d-b85747cecd6b',
2020
cryptr_base_url: 'http://localhost:4000',
2121
dedicated_server: false,
22+
no_popup_no_cookie: false,
2223
};
2324

2425
const validExpiredAccess =

src/models/Cryptr.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const LINKING_ERROR =
99
interface CryptrInterface {
1010
startSecuredView: (
1111
uri: string,
12+
no_popup_no_cookie: boolean,
1213
successCallback?: (data: any) => any,
1314
errorCallback?: (error: any) => any
1415
) => any;

src/models/CryptrProvider.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ const CryptrProvider: React.FC<ProviderProps> = ({
161161
setLoading();
162162
Cryptr.startSecuredView(
163163
ssoUrl,
164+
config.no_popup_no_cookie,
164165
handleRedirectCalback(ssoTransaction, successCallback),
165166
(error: any) => {
166167
setError(error);
@@ -179,6 +180,7 @@ const CryptrProvider: React.FC<ProviderProps> = ({
179180
setLoading();
180181
Cryptr.startSecuredView(
181182
ssoGatewayURL,
183+
config.no_popup_no_cookie,
182184
handleRedirectCalback(ssoTransaction, successCallback),
183185
(error: any) => {
184186
setError(error);
@@ -201,6 +203,7 @@ const CryptrProvider: React.FC<ProviderProps> = ({
201203
let sloUrl = sloAfterRevokeTokenUrl(config, slo_code);
202204
Cryptr.startSecuredView(
203205
sloUrl,
206+
config.no_popup_no_cookie,
204207
(_d: any) => {
205208
callback && callback(json);
206209
},

src/utils/helpers.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const prepareConfig = (
2929
default_locale: options.default_locale || deviceCryptrLocale(),
3030
default_redirect_uri: options.default_redirect_uri,
3131
dedicated_server: options.dedicated_server || false,
32+
no_popup_no_cookie: options.no_popup_no_cookie || false,
3233
};
3334
};
3435

src/utils/interfaces.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,13 @@ export interface CryptrConfig {
3737
cryptr_base_url?: string;
3838
telemetry?: boolean;
3939
dedicated_server?: boolean;
40+
no_popup_no_cookie?: boolean;
4041
}
4142

4243
export interface PreparedCryptrConfig extends CryptrConfig {
4344
cryptr_base_url: string;
4445
dedicated_server: boolean;
46+
no_popup_no_cookie: boolean;
4547
}
4648

4749
export interface ProviderOptions extends CryptrConfig {}

0 commit comments

Comments
 (0)