add OIDC username + locale
This commit is contained in:
@@ -5,6 +5,8 @@ import { InvalidTokenError } from "../Controller/InvalidTokenError";
|
||||
export interface AuthTokenData {
|
||||
identifier: string; //will be a email if logged in or an uuid if anonymous
|
||||
accessToken?: string;
|
||||
username?: string;
|
||||
locale?: string;
|
||||
}
|
||||
export interface AdminSocketTokenData {
|
||||
authorizedRoomIds: string[]; //the list of rooms the client is authorized to read from.
|
||||
@@ -16,8 +18,8 @@ class JWTTokenManager {
|
||||
return Jwt.verify(token, ADMIN_SOCKETS_TOKEN) as AdminSocketTokenData;
|
||||
}
|
||||
|
||||
public createAuthToken(identifier: string, accessToken?: string) {
|
||||
return Jwt.sign({ identifier, accessToken }, SECRET_KEY, { expiresIn: "30d" });
|
||||
public createAuthToken(identifier: string, accessToken?: string, username?: string, locale?: string) {
|
||||
return Jwt.sign({ identifier, accessToken, username, locale }, SECRET_KEY, { expiresIn: "30d" });
|
||||
}
|
||||
|
||||
public verifyJWTToken(token: string, ignoreExpiration: boolean = false): AuthTokenData {
|
||||
|
||||
@@ -4,6 +4,9 @@ import {
|
||||
OPID_CLIENT_SECRET,
|
||||
OPID_CLIENT_ISSUER,
|
||||
OPID_CLIENT_REDIRECT_URL,
|
||||
OPID_USERNAME_CLAIM,
|
||||
OPID_LOCALE_CLAIM,
|
||||
OPID_ADDITIONAL_SCOPES,
|
||||
} from "../Enum/EnvironmentVariable";
|
||||
|
||||
class OpenIDClient {
|
||||
@@ -26,7 +29,7 @@ class OpenIDClient {
|
||||
public authorizationUrl(state: string, nonce: string, playUri?: string, redirect?: string) {
|
||||
return this.initClient().then((client) => {
|
||||
return client.authorizationUrl({
|
||||
scope: "openid email",
|
||||
scope: "openid email " + OPID_ADDITIONAL_SCOPES,
|
||||
prompt: "login",
|
||||
state: state,
|
||||
nonce: nonce,
|
||||
@@ -36,7 +39,10 @@ class OpenIDClient {
|
||||
});
|
||||
}
|
||||
|
||||
public getUserInfo(code: string, nonce: string): Promise<{ email: string; sub: string; access_token: string }> {
|
||||
public getUserInfo(
|
||||
code: string,
|
||||
nonce: string
|
||||
): Promise<{ email: string; sub: string; access_token: string; username: string; locale: string }> {
|
||||
return this.initClient().then((client) => {
|
||||
return client.callback(OPID_CLIENT_REDIRECT_URL, { code }, { nonce }).then((tokenSet) => {
|
||||
return client.userinfo(tokenSet).then((res) => {
|
||||
@@ -45,6 +51,8 @@ class OpenIDClient {
|
||||
email: res.email as string,
|
||||
sub: res.sub,
|
||||
access_token: tokenSet.access_token as string,
|
||||
username: res[OPID_USERNAME_CLAIM] as string,
|
||||
locale: res[OPID_LOCALE_CLAIM] as string,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user