Files

26 lines
781 B
JavaScript

import { getIdentityApi } from '../utils/extension';
// Chooses how an authorization request is carried out. In a browser extension
// the browser provides `identity.launchWebAuthFlow`, which intercepts the
// provider redirect to a `*.chromiumapp.org` / `*.extensions.allizom.org` URL.
// Everywhere else we fall back to a full-page redirect handled by a callback
// route.
export function selectTransport(identity = getIdentityApi()) {
if (identity) {
return {
kind: 'extension',
redirectUri: (providerId) => identity.getRedirectURL(providerId),
async launch(url) {
return identity.launchWebAuthFlow({ url, interactive: true });
},
};
}
return {
kind: 'web',
redirect(url) {
window.location.href = url;
},
};
}