Fixed auth flow and added scaffolding vite config.

This commit is contained in:
SamTV12345 2024-03-24 21:12:58 +01:00
parent 66fc735253
commit 04e4a5eee0
18 changed files with 226 additions and 37 deletions

View file

@ -27,7 +27,6 @@ const configuration: Configuration = {
],
scopes: ['openid', 'profile', 'email'],
findAccount: async (ctx, id) => {
console.log("Finding account", id)
return {
accountId: id,
claims: () => ({
@ -71,7 +70,6 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
const {login, password} = (await formid.parse(req))[0]
const {prompt, jti, session, params, grantId} = await oidc.interactionDetails(req, res);
console.log("Session is", session)
switch (prompt.name) {
case 'login': {
@ -131,8 +129,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
}
await next();
} catch (err) {
console.log(err)
return next(err);
return res.writeHead(500).end(err.message);
}
})
@ -143,10 +140,8 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
uid, prompt, params, session,
} = await oidc.interactionDetails(req, res);
console.log("Params are", params)
params["state"] = uid
console.log("Prompt is", prompt)
switch (prompt.name) {
case 'login': {
res.redirect(format({
@ -156,7 +151,6 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
break
}
case 'consent': {
console.log("Consent")
res.redirect(format({
pathname: '/views/consent',
query: params as ParsedUrlQuery
@ -180,22 +174,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
res.sendFile(path.join(settings.root,'src','static', 'oidc','consent.html'));
})
args.app.get('/interaction/:uid/confirm', async (req, res) => {
const {uid, prompt, params} = await oidc.interactionDetails(req, res);
console.log('interaction', uid, prompt, params);
res.render('interaction', {
uid,
prompt,
params,
title: 'Authorize',
client: await oidc.Client.find(params.client_id!),
});
})
args.app.get('/interaction/:uid', async (req, res) => {
return res.sendFile(path.join(settings.root,'src','static', 'oidc','login.html'));
})
/*
oidc.on('authorization.error', (ctx, error) => {
console.log('authorization.error', error);
})
@ -211,7 +190,7 @@ export const expressCreateServer = async (hookName: string, args: ArgsExpressTyp
})
oidc.on('revocation.error', (ctx, error) => {
console.log('revocation.error', error);
})
})*/
args.app.use("/oidc", oidc.callback());
//cb();
}

View file

@ -68,7 +68,6 @@ class MemoryAdapter implements Adapter{
find(id: string): Promise<AdapterPayload | void | undefined> {
const foundSession = storage.get(this.key(id)) as AdapterPayload;
console.log("find", id, foundSession);
if (storage.has(this.key(id))){
return Promise.resolve<AdapterPayload>(storage.get(this.key(id)) as AdapterPayload);
}
@ -76,7 +75,6 @@ class MemoryAdapter implements Adapter{
}
findByUserCode(userCode: string) {
console.log("findByUserCode", userCode);
const id = storage.get(userCodeKeyFor(userCode)) as string;
return this.find(id);
}
@ -99,14 +97,11 @@ class MemoryAdapter implements Adapter{
}
findByUid(uid: string): Promise<AdapterPayload | void | undefined> {
console.log("findByUid", uid);
for(const [_, value] of storage.entries()){
if(typeof value ==="object" && "uid" in value && value.uid === uid){
console.log("found", value);
return Promise.resolve(value);
}
}
console.log("not found");
return Promise.resolve(undefined);
}

View file

@ -26,17 +26,14 @@
body: JSON.stringify(data),
}).then(response => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok.');
}).then(data => {
if (data.status === 'success') {
window.location.href = data.redirect;
if (response.redirected) {
window.location.href = response.url;
}
} else {
document.getElementById('error').innerText = "Error signing in";
}
}).catch(error => {
console.error('There has been a problem with your fetch operation:', error);
document.getElementById('error').innerText = "Error signing in"+error;
});
});
}