Skip to content

Commit

Permalink
disable SSO for oidcConformant + first class nonce and state
Browse files Browse the repository at this point in the history
  • Loading branch information
glena committed Jan 4, 2017
1 parent 52ce194 commit c0d332e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
15 changes: 13 additions & 2 deletions src/core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export function setup(id, clientID, domain, options, hookRunner, emitEventFn) {
emitEventFn: emitEventFn,
hookRunner: hookRunner,
useTenantInfo: options.__useTenantInfo || false,
oidcConformant: options.oidcConformant || false,
hashCleanup: options.hashCleanup === false ? false : true,
allowedConnections: Immutable.fromJS(options.allowedConnections || []),
ui: extractUIOptions(id, options),
Expand Down Expand Up @@ -69,6 +70,10 @@ export function useTenantInfo(m) {
return get(m, "useTenantInfo");
}

export function oidcConformant(m) {
return get(m, "oidcConformant");
}

export function languageBaseUrl(m) {
return get(m, "languageBaseUrl");
}
Expand Down Expand Up @@ -208,7 +213,9 @@ function extractAuthOptions(options) {
redirectUrl,
responseMode,
responseType,
sso
sso,
state,
nonce
} = options.auth || {};

audience = typeof audience === "string" ? audience : undefined;
Expand All @@ -217,6 +224,8 @@ function extractAuthOptions(options) {
redirectUrl = typeof redirectUrl === "string" && redirectUrl ? redirectUrl : window.location.href;
redirect = typeof redirect === "boolean" ? redirect : true;
responseMode = typeof responseMode === "string" ? responseMode : undefined;
state = typeof state === "string" ? state : undefined;
nonce = typeof nonce === "string" ? nonce : undefined;
responseType = typeof responseType === "string" ? responseType : redirectUrl ? "code" : "token";

sso = typeof sso === "boolean" ? sso : true;
Expand All @@ -233,7 +242,9 @@ function extractAuthOptions(options) {
redirectUrl,
responseMode,
responseType,
sso
sso,
state,
nonce
});
}

Expand Down
32 changes: 17 additions & 15 deletions src/core/remote_data.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,25 @@ export function syncRemoteData(m) {
});
}

m = sync(m, "sso", {
conditionFn: l.auth.sso,
waitFn: m => isSuccess(m, "client"),
syncFn: (m, cb) => fetchSSOData(l.id(m), isADEnabled(m), cb),
successFn: (m, result) => m.mergeIn(["sso"], Immutable.fromJS(result)),
errorFn: (m, error) => {
// location.origin is not supported in all browsers
let origin = location.protocol + "//" + location.hostname;
if (location.port) {
origin += ":" + location.port;
}
if (!l.oidcConformant(m)) {
m = sync(m, "sso", {
conditionFn: l.auth.sso,
waitFn: m => isSuccess(m, "client"),
syncFn: (m, cb) => fetchSSOData(l.id(m), isADEnabled(m), cb),
successFn: (m, result) => m.mergeIn(["sso"], Immutable.fromJS(result)),
errorFn: (m, error) => {
// location.origin is not supported in all browsers
let origin = location.protocol + "//" + location.hostname;
if (location.port) {
origin += ":" + location.port;
}

const appSettingsUrl = `https://manage.auth0.com/#/applications/${l.clientID(m)}/settings`;
const appSettingsUrl = `https://manage.auth0.com/#/applications/${l.clientID(m)}/settings`;

l.warn(m, `There was an error fetching the SSO data. This could simply mean that there was a problem with the network. But, if a "Origin" error has been logged before this warning, please add "${origin}" to the "Allowed Origins (CORS)" list in the Auth0 dashboard: ${appSettingsUrl}`);
}
});
l.warn(m, `There was an error fetching the SSO data. This could simply mean that there was a problem with the network. But, if a "Origin" error has been logged before this warning, please add "${origin}" to the "Allowed Origins (CORS)" list in the Auth0 dashboard: ${appSettingsUrl}`);
}
});
}

return m;
}
8 changes: 6 additions & 2 deletions src/core/web_api/legacy_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ class Auth0LegacyAPIClient {
this.authOpt = {
popup: !opts.redirect,
popupOptions: opts.popupOptions,
sso: opts.sso
sso: opts.sso,
nonce: opts.nonce,
state: opts.state
};
}

Expand Down Expand Up @@ -77,7 +79,9 @@ class Auth0LegacyAPIClient {

parseHash(hash = '', cb) {
return this.client.parseHash({
hash: decodeURIComponent(hash)
hash: decodeURIComponent(hash),
nonce: this.authOpt.nonce,
state: this.authOpt.state
}, cb);
}

Expand Down
8 changes: 6 additions & 2 deletions src/core/web_api/p2_api.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ class Auth0APIClient {
this.authOpt = {
popup: !opts.redirect,
popupOptions: opts.popupOptions,
sso: opts.sso
sso: opts.sso,
nonce: opts.nonce,
state: opts.state
};
}

Expand Down Expand Up @@ -74,7 +76,9 @@ class Auth0APIClient {

parseHash(hash = '', cb) {
return this.client.parseHash({
hash: decodeURIComponent(hash)
hash: decodeURIComponent(hash),
nonce: this.authOpt.nonce,
state: this.authOpt.state
}, cb);
}

Expand Down

0 comments on commit c0d332e

Please sign in to comment.