mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-12-03 09:38:54 +00:00
fix(oauth): userinfo reports email_verified only for an address the account did not set itself
The userinfo endpoint answered email_verified: true for every account, although nobody had confirmed the address. It now follows users.email_self_asserted, the same mark the SSO login uses before it links an account by email.
This commit is contained in:
@@ -41,6 +41,7 @@ export interface OauthTokenWithUserRow {
|
||||
username: string;
|
||||
email: string;
|
||||
role: string;
|
||||
email_self_asserted: number;
|
||||
}
|
||||
|
||||
/** OA17 (`findChainRoot`'s upward-walk read). */
|
||||
@@ -268,6 +269,7 @@ export class OauthTokensRepository extends TrekRepository<OauthTokens> {
|
||||
'u.username',
|
||||
'u.email',
|
||||
'u.role',
|
||||
'u.email_self_asserted',
|
||||
])
|
||||
.where({ 'ot.access_token_hash': hash })
|
||||
.execute<OauthTokenWithUserRow | undefined>('get', false);
|
||||
|
||||
@@ -220,7 +220,7 @@ export class OauthPublicController {
|
||||
res.json({
|
||||
sub: String(info.user.id),
|
||||
email: info.user.email,
|
||||
email_verified: true,
|
||||
email_verified: info.emailVerified,
|
||||
preferred_username: info.user.username,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -73,6 +73,8 @@ function expiriesAsIso(row: { access_token_expires_at: string; refresh_token_exp
|
||||
|
||||
export interface OAuthTokenInfo {
|
||||
user: User;
|
||||
/** False when the account typed its email in itself; nobody has confirmed that address. */
|
||||
emailVerified: boolean;
|
||||
scopes: string[];
|
||||
clientId: string;
|
||||
audience: string | null;
|
||||
@@ -450,6 +452,7 @@ export class OauthService {
|
||||
|
||||
return {
|
||||
user: { id: row.user_id, username: row.username, email: row.email, role: row.role as 'admin' | 'user' },
|
||||
emailVerified: !row.email_self_asserted,
|
||||
scopes: decodeJson(OAUTH_TOKEN_SCOPES, row.scopes, `client ${row.client_id} user ${row.user_id}`),
|
||||
clientId: row.client_id,
|
||||
audience: row.audience ?? null,
|
||||
|
||||
Reference in New Issue
Block a user