@aws-amplify/auth
Version:
Auth category of aws-amplify
49 lines (47 loc) • 1.91 kB
JavaScript
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
Object.defineProperty(exports, "__esModule", { value: true });
exports.attemptCompleteOAuthFlow = void 0;
const utils_1 = require("@aws-amplify/core/internals/utils");
const utils_2 = require("../../../../utils");
const oAuthStore_1 = require("./oAuthStore");
const completeOAuthFlow_1 = require("./completeOAuthFlow");
const getRedirectUrl_1 = require("./getRedirectUrl");
const handleFailure_1 = require("./handleFailure");
const attemptCompleteOAuthFlow = async (authConfig) => {
try {
(0, utils_1.assertTokenProviderConfig)(authConfig);
(0, utils_1.assertOAuthConfig)(authConfig);
oAuthStore_1.oAuthStore.setAuthConfig(authConfig);
}
catch (_) {
// no-op
// This should not happen as Amplify singleton checks the oauth config key
// unless the oauth config object doesn't contain required properties
return;
}
// No inflight OAuth
if (!(await oAuthStore_1.oAuthStore.loadOAuthInFlight())) {
return;
}
try {
const currentUrl = window.location.href;
const { loginWith, userPoolClientId } = authConfig;
const { domain, redirectSignIn, responseType } = loginWith.oauth;
const redirectUri = (0, getRedirectUrl_1.getRedirectUrl)(redirectSignIn);
await (0, completeOAuthFlow_1.completeOAuthFlow)({
currentUrl,
clientId: userPoolClientId,
domain,
redirectUri,
responseType,
userAgentValue: (0, utils_2.getAuthUserAgentValue)(utils_1.AuthAction.SignInWithRedirect),
});
}
catch (err) {
await (0, handleFailure_1.handleFailure)(err);
}
};
exports.attemptCompleteOAuthFlow = attemptCompleteOAuthFlow;
//# sourceMappingURL=attemptCompleteOAuthFlow.js.map
;