add astro template for front #13
14468
front/package-lock.json
generated
Normal file
14468
front/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,14 +1,10 @@
|
|||||||
---
|
---
|
||||||
|
|
||||||
const pb = Astro.locals.pb
|
const pb = Astro.locals.pb
|
||||||
const redirectUrl = Astro.url.protocol + "//" + Astro.url.host + '/account/oauth';
|
const redirectUrl = Astro.url.protocol + "//" + Astro.url.host + '/account/oauth';
|
||||||
|
|
||||||
console.log(redirectUrl)
|
|
||||||
|
|
||||||
const params = Astro.url.searchParams
|
const params = Astro.url.searchParams
|
||||||
|
|
||||||
const code = params.get('code')
|
const code = params.get('code')
|
||||||
|
|
||||||
|
console.log(redirectUrl)
|
||||||
console.log(Astro.request.headers.get('cookie'))
|
console.log(Astro.request.headers.get('cookie'))
|
||||||
//TODO socké dans les cookies
|
//TODO socké dans les cookies
|
||||||
// load the previously stored provider's data
|
// load the previously stored provider's data
|
||||||
@ -31,12 +27,11 @@ if (provider.state !== params.get('state')) {
|
|||||||
throw "State parameters don't match.";
|
throw "State parameters don't match.";
|
||||||
}
|
}
|
||||||
|
|
||||||
pb.collection('users').authWithOAuth2Code(
|
await pb.collection('users').authWithOAuth2Code(
|
||||||
provider.name,
|
provider.name,
|
||||||
code,
|
code,
|
||||||
provider.codeVerifier,
|
provider.codeVerifier,
|
||||||
redirectUrl,
|
redirectUrl,
|
||||||
// pass optional user create data
|
|
||||||
{
|
{
|
||||||
emailVisibility: false,
|
emailVisibility: false,
|
||||||
}
|
}
|
||||||
@ -44,11 +39,15 @@ pb.collection('users').authWithOAuth2Code(
|
|||||||
//REDIRECT
|
//REDIRECT
|
||||||
console.log("oauth OK !!");
|
console.log("oauth OK !!");
|
||||||
console.log(JSON.stringify(authData, null, 2));
|
console.log(JSON.stringify(authData, null, 2));
|
||||||
|
console.log(pb.authStore.isValid);
|
||||||
|
console.log(pb.authStore.isValid);
|
||||||
|
return Astro.redirect("/account")
|
||||||
}).catch((err) => {
|
}).catch((err) => {
|
||||||
console.log("oauth fail !!");
|
console.log("oauth fail !!");
|
||||||
console.log(err);
|
console.log(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
||||||
@ -59,39 +58,5 @@ pb.collection('users').authWithOAuth2Code(
|
|||||||
<title>OAuth2 redirect page</title>
|
<title>OAuth2 redirect page</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<pre id="content">Authenticating...</pre>
|
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/gh/pocketbase/js-sdk@master/dist/pocketbase.umd.js"></script>
|
|
||||||
<script type="text/javascript">
|
|
||||||
const pb = new PocketBase("http://127.0.0.1:8090");
|
|
||||||
const redirectUrl = 'http://127.0.0.1:8090/redirect.html';
|
|
||||||
|
|
||||||
// parse the query parameters from the redirected url
|
|
||||||
const params = (new URL(window.location)).searchParams;
|
|
||||||
|
|
||||||
// load the previously stored provider's data
|
|
||||||
const provider = JSON.parse(localStorage.getItem('provider'))
|
|
||||||
|
|
||||||
// compare the redirect's state param and the stored provider's one
|
|
||||||
if (provider.state !== params.get('state')) {
|
|
||||||
throw "State parameters don't match.";
|
|
||||||
}
|
|
||||||
|
|
||||||
// authenticate
|
|
||||||
pb.collection('users').authWithOAuth2Code(
|
|
||||||
provider.name,
|
|
||||||
params.get('code'),
|
|
||||||
provider.codeVerifier,
|
|
||||||
redirectUrl,
|
|
||||||
// pass optional user create data
|
|
||||||
{
|
|
||||||
emailVisibility: false,
|
|
||||||
}
|
|
||||||
).then((authData) => {
|
|
||||||
document.getElementById('content').innerText = JSON.stringify(authData, null, 2);
|
|
||||||
}).catch((err) => {
|
|
||||||
document.getElementById('content').innerText = "Failed to exchange code.\n" + err;
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user