latest dev + i18n
This commit is contained in:
@@ -91,7 +91,7 @@ export class AuthenticateController extends BaseController {
|
||||
const resCheckTokenAuth = await openIDClient.checkTokenAuth(authTokenData.accessToken);
|
||||
res.writeStatus("200");
|
||||
this.addCorsHeaders(res);
|
||||
return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, username: authTokenData.username, authToken: token }));
|
||||
return res.end(JSON.stringify({ ...resCheckTokenAuth, ...resUserData, username: authTokenData.username, locale: authTokenData.locale, authToken: token }));
|
||||
} catch (err) {
|
||||
console.info("User was not connected", err);
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export class AuthenticateController extends BaseController {
|
||||
if (!sub) {
|
||||
throw new Error("No sub in the response");
|
||||
}
|
||||
const authToken = jwtTokenManager.createAuthToken(sub, userInfo?.access_token, userInfo?.username);
|
||||
const authToken = jwtTokenManager.createAuthToken(sub, userInfo?.access_token, userInfo?.username, userInfo.locale);
|
||||
|
||||
//Get user data from Admin Back Office
|
||||
//This is very important to create User Local in LocalStorage in WorkAdventure
|
||||
@@ -121,7 +121,7 @@ export class AuthenticateController extends BaseController {
|
||||
|
||||
res.writeStatus("200");
|
||||
this.addCorsHeaders(res);
|
||||
return res.end(JSON.stringify({ ...data, authToken, username: userInfo.username, userUuid : sub }));
|
||||
return res.end(JSON.stringify({ ...data, authToken, username: userInfo.username, locale: userInfo.locale, userUuid : sub }));
|
||||
} catch (e) {
|
||||
console.error("openIDCallback => ERROR", e);
|
||||
return this.errorToResponse(e, res);
|
||||
|
||||
@@ -6,6 +6,7 @@ export interface AuthTokenData {
|
||||
identifier: string; //will be a sub (id) 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.
|
||||
@@ -17,8 +18,8 @@ class JWTTokenManager {
|
||||
return Jwt.verify(token, ADMIN_SOCKETS_TOKEN) as AdminSocketTokenData;
|
||||
}
|
||||
|
||||
public createAuthToken(identifier: string, accessToken?: string, username?: string) {
|
||||
return Jwt.sign({ identifier, accessToken, username }, 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 {
|
||||
|
||||
@@ -26,7 +26,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 profile email",
|
||||
prompt: "login",
|
||||
state: state,
|
||||
nonce: nonce,
|
||||
@@ -36,7 +36,7 @@ class OpenIDClient {
|
||||
});
|
||||
}
|
||||
|
||||
public getUserInfo(code: string, nonce: string): Promise<{ email: string; sub: string; access_token: string; username: 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) => {
|
||||
@@ -46,6 +46,7 @@ class OpenIDClient {
|
||||
sub: res.sub,
|
||||
access_token: tokenSet.access_token as string,
|
||||
username: (res.preferred_username || res.username || res.nickname || res.name || res.email) as string,
|
||||
locale: res.locale as string,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user