Skip to content

Commit 44a7789

Browse files
authored
Merge pull request #25 from thivi/feature/safari_issue
Fix issues caused in the Safari browser
2 parents 5f0e18e + a0897b4 commit 44a7789

File tree

12 files changed

+75
-67
lines changed

12 files changed

+75
-67
lines changed

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ Before trying out the sample apps, you need to a create a service provider in th
9494

9595
4. Under `Allowed Grant Types` uncheck everything except `Code` and `Refresh Token`.
9696

97-
5. Enter `http://localhost:3000` as the `Callback Url`.
97+
5. Enter the Callback URL(s). You can find the relevant callback URL(s) of each sample app in the [Running the sample apps](#2.-running-the-sample-apps) section.
9898

9999
6. Check `Allow authentication without the client secret`.
100100

101101
7. Click `Add` at the bottom.
102102

103103
8. Copy the `OAuth Client Key`.
104104

105+
9. Enable CORS for the client application by following this guide (https://is.docs.wso2.com/en/5.11.0/learn/cors/).
106+
105107
### 2. Running the sample apps
106108

107109
Build the apps by running the following command at the root directory.
@@ -111,14 +113,20 @@ npm run build
111113

112114
#### 1. Vanilla JavaScript Sample
113115

116+
The *Callback URL* of this app is `http://localhost:3000`.
117+
114118
You can try out the Vanilla JavaScript Sample App from the [samples/vanilla-js-app](samples/vanilla-js-app). The instructions to run the app can be found [here](/samples/vanilla-js-app/README.md)
115119

116120
#### 2. React Sample
117121

122+
The *Callback URL* of this app is `regexp=(http://localhost:3000/sign-in|http://localhost:3000/dashboard)`.
123+
118124
You can try out the React Sample App from the [samples/react-js-app](samples/react-js-app). The instructions to run the app can be found [here](/samples/react-js-app/README.md)
119125

120126
#### 2. Java Webapp Sample
121127

128+
The *Callback URL* of this app is the URL of this app on the server. For instance, if your Tomcat server is running on `http://localhost:8080`, then the callback URL will be `http://localhost:8080/java-webapp`.
129+
122130
You can try out the Java Webapp Sample App from the [samples/java-webapp](samples/java-webapp). The instructions to run the app can be found [here](/samples/java-webapp/README.md)
123131

124132
## APIs
@@ -176,7 +184,7 @@ Of the three methods, storing the session information in the **web worker** is t
176184
|`oidcSessionIFrame`|`string`| `"/oidc/checksession"`| The URL of the OIDC session iframe.
177185
|`revoke`|`string`| `"/oauth2/revoke"`| The endpoint to send the revoke-access-token request to.
178186
|`token`|`string`| `"/oauth2/token"`| The endpoint to send the token request to.|
179-
|`wellKnown`|`string`| `"/oauth2/oidcdiscovery/.well-known/openid-configuration"`| The endpoint to receive the OIDC endpoints from|
187+
|`wellKnown`|`string`| `"/oauth2/oidcdiscovery/.well-known/openid-configuration"`| The endpoint to receive the OIDC endpoints from|
180188

181189
```javascript
182190
auth.initialize(config);
@@ -191,7 +199,7 @@ This method returns the information about the authenticated user as an object. T
191199
|`email`|`string`|The email address of the user|
192200
|`username`|`string`| The username of the user|
193201
|`displayName`| `string`| The display name of the user|
194-
`allowedScopes`|`string`| The scopes the user has authorized the client to access|
202+
`allowedScopes`|`string`| The scopes the user has authorized the client to access|
195203

196204
```javascript
197205
auth.getUserInfo().then((response) => {

oidc-js/package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"types": "dist/src/index.d.ts",
1313
"scripts": {
1414
"lint": "eslint --ext .js,.ts .",
15+
"fix-lint": "eslint --ext .js,.ts . --fix",
1516
"build": "rimraf dist && npm run type-check && webpack -p --env.NODE_ENV=production",
1617
"type-check": "tsc --emitDeclarationOnly",
1718
"type-check:watch": "npm run type-check -- --watch",
@@ -62,5 +63,8 @@
6263
"bugs": {
6364
"url": "https://github.com/asgardio/asgardio-js-oidc-sdk/issues"
6465
},
65-
"homepage": "https://github.com/asgardio/asgardio-js-oidc-sdk#readme"
66+
"homepage": "https://github.com/asgardio/asgardio-js-oidc-sdk#readme",
67+
"browserslist": [
68+
"> 0.2%"
69+
]
6670
}

oidc-js/src/client.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import { AxiosError, AxiosRequestConfig, AxiosResponse } from "axios";
2020
import { ACCESS_TOKEN, AUTHORIZATION_CODE_TYPE, Hooks, OIDC_SCOPE, Storage } from "./constants";
21+
import { isWebWorkerConfig } from "./helpers";
2122
import { AxiosHttpClient, AxiosHttpClientInstance } from "./http-client";
2223
import {
2324
ConfigInterface,
@@ -26,8 +27,7 @@ import {
2627
ServiceResourcesType,
2728
UserInfo,
2829
WebWorkerClientInterface,
29-
WebWorkerConfigInterface,
30-
isWebWorkerConfig
30+
WebWorkerConfigInterface
3131
} from "./models";
3232
import {
3333
customGrant as customGrantUtil,
@@ -193,6 +193,8 @@ export class IdentityClient {
193193
if (this._onSignInCallback) {
194194
if (response.allowedScopes || response.displayName || response.email || response.username) {
195195
this._onSignInCallback(response);
196+
} else {
197+
this._onSignInCallback(null);
196198
}
197199
}
198200

@@ -351,7 +353,7 @@ export class IdentityClient {
351353
throw Error("Identity Client has not been initialized yet");
352354
}
353355

354-
public getDecodedIDToken(): Promise<DecodedIdTokenPayloadInterface>{
356+
public getDecodedIDToken(): Promise<DecodedIdTokenPayloadInterface> {
355357
if (this._storage === Storage.WebWorker) {
356358
return this._client.getDecodedIDToken();
357359
}

oidc-js/src/helpers/index.ts

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/**
2+
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
export * from "./typeguards";

oidc-js/src/helpers/semaphore.ts

-48
This file was deleted.

oidc-js/src/helpers/typeguards.ts

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Copyright (c) 2020, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
19+
import { Storage } from "../constants";
20+
import { ConfigInterface, WebWorkerConfigInterface } from "../models";
21+
22+
export const isWebWorkerConfig = (
23+
config: ConfigInterface | WebWorkerConfigInterface
24+
): config is WebWorkerConfigInterface => {
25+
return config.storage === Storage.WebWorker;
26+
};

oidc-js/src/models/client.ts

-6
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,3 @@ export interface HttpClient {
6464
export interface WebWorkerClientConfigInterface extends WebWorkerConfigInterface {
6565
httpClient: HttpClient;
6666
}
67-
68-
export const isWebWorkerConfig = (
69-
config: ConfigInterface | WebWorkerConfigInterface
70-
): config is WebWorkerConfigInterface => {
71-
return config.storage === Storage.WebWorker;
72-
};

oidc-js/src/utils/sign-in.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ import {
6060
USERNAME,
6161
USERNAME_TAG
6262
} from "../constants";
63+
import { isWebWorkerConfig } from "../helpers";
6364
import {
6465
AuthenticatedUserInterface,
6566
ConfigInterface,
@@ -69,8 +70,7 @@ import {
6970
TokenRequestHeader,
7071
TokenResponseInterface,
7172
UserInfo,
72-
WebWorkerConfigInterface,
73-
isWebWorkerConfig
73+
WebWorkerConfigInterface
7474
} from "../models";
7575

7676
/**

oidc-js/src/utils/sign-out.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ import {
2424
SIGN_OUT_REDIRECT_URL
2525
} from "../constants";
2626
import { Storage } from "../constants/storage";
27-
import { ConfigInterface, WebWorkerConfigInterface, isWebWorkerConfig } from "../models";
27+
import { isWebWorkerConfig } from "../helpers";
28+
import { ConfigInterface, WebWorkerConfigInterface } from "../models";
2829

2930
/**
3031
* Execute user sign out request
@@ -60,7 +61,7 @@ export function sendSignOutRequest(requestParams: ConfigInterface | WebWorkerCon
6061
`${ logoutEndpoint }?` + `id_token_hint=${ idToken }` + `&post_logout_redirect_uri=${ callbackURL }&state=`
6162
+ LOGOUT_SUCCESS;
6263

63-
if (requestParams.storage !== Storage.WebWorker) {
64+
if (!isWebWorkerConfig(requestParams)) {
6465
window.location.href = logoutCallback;
6566

6667
return Promise.resolve(true);

oidc-js/src/worker/web-worker.ts

+1
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export const WebWorker: WebWorkerSingletonInterface = (function (): WebWorkerSin
320320
*/
321321
function Constructor(config: WebWorkerClientConfigInterface): WebWorkerInterface {
322322
authConfig = { ...config };
323+
session.clear();
323324
authConfig.session = session;
324325

325326
if (authConfig.authorizationCode) {

oidc-js/tsconfig.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@
2121
"outDir": "./dist"
2222
},
2323
"compileOnSave": false,
24-
"exclude": ["node_modules", "test-configs", "src/**/tests/*", "**/*.test.ts"]
24+
"exclude": ["node_modules", "test-configs", "src/**/tests/*", "**/*.test.ts", "dist/**/*"]
2525
}

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"prebuild": "npm install && lerna bootstrap",
99
"remove-node-modules": "npx lerna exec -- rimraf -rf node_modules && rimraf -rf node_modules",
1010
"remove-package-lock": "npx lerna exec -- rimraf -rf package-lock.json && rimraf -rf package-lock.json",
11-
"lint": "eslint --ext .js,.ts .",
11+
"lint": "lerna run lint",
12+
"fix-lint": "lerna run fix-lint",
1213
"clean": "lerna run clean --stream",
1314
"clean-all": "npm run remove-package-lock && npm run remove-node-modules",
1415
"bump-patch-version": "lerna version patch --yes",

0 commit comments

Comments
 (0)