.
This commit is contained in:
parent
774a6864a2
commit
c230de4915
1 changed files with 7 additions and 5 deletions
12
client.ts
12
client.ts
|
|
@ -19,7 +19,7 @@ const app = express();
|
||||||
|
|
||||||
const database: Record<
|
const database: Record<
|
||||||
string,
|
string,
|
||||||
{ oidConfig: oid.Configuration; pkceCodeVerifier: string }
|
{ oidConfig: oid.Configuration; pkceCodeVerifier: string, url: string }
|
||||||
> = {};
|
> = {};
|
||||||
|
|
||||||
app.get("/login", async (req, res) => {
|
app.get("/login", async (req, res) => {
|
||||||
|
|
@ -30,6 +30,7 @@ app.get("/login", async (req, res) => {
|
||||||
}
|
}
|
||||||
const cbid = uid();
|
const cbid = uid();
|
||||||
const redirect_uri = `${CLIENT_URL}/callback/${cbid}`;
|
const redirect_uri = `${CLIENT_URL}/callback/${cbid}`;
|
||||||
|
console.log("Redirect URI is", redirect_uri)
|
||||||
const provider = new URL(req.query.provider);
|
const provider = new URL(req.query.provider);
|
||||||
const oidConfig = await oid.dynamicClientRegistration(
|
const oidConfig = await oid.dynamicClientRegistration(
|
||||||
provider,
|
provider,
|
||||||
|
|
@ -44,7 +45,7 @@ app.get("/login", async (req, res) => {
|
||||||
);
|
);
|
||||||
const pkceCodeVerifier = oid.randomPKCECodeVerifier();
|
const pkceCodeVerifier = oid.randomPKCECodeVerifier();
|
||||||
const code_challenge = await oid.calculatePKCECodeChallenge(pkceCodeVerifier);
|
const code_challenge = await oid.calculatePKCECodeChallenge(pkceCodeVerifier);
|
||||||
database[cbid] = { oidConfig, pkceCodeVerifier };
|
database[cbid] = { oidConfig, pkceCodeVerifier, url: redirect_uri };
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
delete database[cbid];
|
delete database[cbid];
|
||||||
}, 600000 /* 10 minutes */);
|
}, 600000 /* 10 minutes */);
|
||||||
|
|
@ -65,9 +66,10 @@ app.get("/callback/:cbid", async (req, res) => {
|
||||||
res.end();
|
res.end();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const { oidConfig, pkceCodeVerifier } = database[cbid]!;
|
const { oidConfig, pkceCodeVerifier, url: redirect_uri } = database[cbid]!;
|
||||||
const fullUrl = `${req.protocol}://${req.get("host")}${req.url}`;
|
const url = new URL(redirect_uri + req.query);
|
||||||
const url = new URL(fullUrl);
|
console.log("URL")
|
||||||
|
console.log(redirect_uri + req.query);
|
||||||
let tokens = await oid
|
let tokens = await oid
|
||||||
.authorizationCodeGrant(oidConfig, url, {
|
.authorizationCodeGrant(oidConfig, url, {
|
||||||
pkceCodeVerifier,
|
pkceCodeVerifier,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue