Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function fetchOAuthRedirect(oAuthProvider) {
- return await fetch(
- `http://localhost:8080/api/auth/authorisationurl?thirdPartyId=${oAuthProvider}`,
- {
- method: 'GET',
- headers: {
- rid: 'thirdparty',
- },
- },
- ).then((response) => response.json());
- }
- function appendRedirectUri(url, oAuthProvider) {
- let urlObj = new URL(url);
- urlObj.searchParams.append(
- 'redirect_uri',
- `http://localhost:8080/api/auth/callback/${oAuthProvider}`,
- );
- return urlObj.toString();
- }
- async function doSignInUp(code, thirdPartyId) {
- return await fetch('http://localhost:8080/api/auth/signinup', {
- method: 'POST',
- headers: {
- rid: 'thirdparty',
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({
- code,
- redirectURI: 'http://localhost:8080/auth/callback/github',
- thirdPartyId: thirdPartyId,
- }),
- });
- }
- async function signinup(oAuthProvider) {
- const redirect = await fetchOAuthRedirect(oAuthProvider);
- window.location.href = appendRedirectUri(redirect.url, oAuthProvider);
- //I don't understand where exactly I should place code down below, cause it's obvious that it's unreachable after the user is redirected to the third party auth page.
- let code = new URL(window.location.href).searchParams.get('code');
- const response = await doSignInUp(code, oAuthProvider);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement