diff --git a/package.json b/package.json index 7ab2697..d584b28 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@icynet/oauth2-provider", - "version": "1.0.5", + "version": "1.0.6", "description": "OAuth2.0 Provider for Icy Network", "main": "dist/index.js", "types": "dist/index.d.ts", diff --git a/src/controller/authorization.ts b/src/controller/authorization.ts index 7de7346..c633ed4 100644 --- a/src/controller/authorization.ts +++ b/src/controller/authorization.ts @@ -5,6 +5,7 @@ import { UnauthorizedClient, InvalidScope, AccessDenied, + InteractionRequired, } from '../model/error'; import { OAuth2User } from '../model/model'; import { data as dataResponse } from '../utils/response'; @@ -137,21 +138,30 @@ export const authorization = wrap(async (req, res) => { req.oauth2.logger.debug('User fetched from request'); } + const prompt = ((req.query.prompt || '') as string).split(' '); let resObj: Record = {}; let consented = false; if (req.method === 'GET') { // Check if the user has already consented to this client with this scope - // TODO: reevaluate security implications consented = await oauth2.model.user.consented( oauth2.model.user.getId(user), oauth2.model.client.getId(client), scope ); + if (!consented && prompt.includes('none')) { + throw new InteractionRequired('Interaction required!'); + } + // Ask for consent - if (!consented) + if (!consented || ( + prompt.includes('login') || + prompt.includes('consent') || + prompt.includes('select_account') + )) { return oauth2.decision(req, res, client, scope, user, redirectUri); + } } // Save consent diff --git a/src/model/error.ts b/src/model/error.ts index 6ba17c3..0ed241c 100644 --- a/src/model/error.ts +++ b/src/model/error.ts @@ -92,3 +92,12 @@ export class UnsupportedResponseType extends OAuth2Error { super('unsupported_response_type', msg, 400); } } + +export class InteractionRequired extends OAuth2Error { + public name = 'OAuth2InteractionRequired'; + public logLevel = 'info'; + + constructor(msg: string) { + super('interaction_required', msg, 400); + } +}