keep plan selection during keycloak hop
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { KeycloakUser } from 'src/models/main.model';
|
||||
|
||||
import urlcat from 'urlcat';
|
||||
@Injectable()
|
||||
export class AuthService {
|
||||
public async getAccessToken() {
|
||||
@@ -50,21 +50,40 @@ export class AuthService {
|
||||
const data = await response.json();
|
||||
return data as KeycloakUser[];
|
||||
}
|
||||
// public async getUser(userid: string) {
|
||||
// const token = await this.getAccessToken();
|
||||
// const URLPATH = `${process.env.KEYCLOAK_ADMIN_REALM}${process.env.REALM}${process.env.KEYCLOAK_USER_URL}`;
|
||||
// const URL = urlcat(process.env.KEYCLOAK_HOST, URLPATH, { userid });
|
||||
// const response = await ky
|
||||
// .get(URL, {
|
||||
// headers: {
|
||||
// 'Content-Type': 'application/x-www-form-urlencoded',
|
||||
// Authorization: `Bearer ${token}`,
|
||||
// },
|
||||
// })
|
||||
// .json();
|
||||
// return response;
|
||||
// }
|
||||
|
||||
public async getUser(userid: string): Promise<KeycloakUser> {
|
||||
const token = await this.getAccessToken();
|
||||
const URLPATH = `${process.env.KEYCLOAK_ADMIN_REALM}${process.env.REALM}${process.env.KEYCLOAK_USER_URL}`;
|
||||
const URL = urlcat(process.env.KEYCLOAK_HOST, URLPATH, { userid });
|
||||
const response = await fetch(URL, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
const data = await response.json();
|
||||
return data as KeycloakUser;
|
||||
}
|
||||
public async updateKeycloakUser(keycloakUser: KeycloakUser): Promise<void> {
|
||||
const token = await this.getAccessToken();
|
||||
const userid = keycloakUser.id;
|
||||
const URLPATH = `${process.env.KEYCLOAK_ADMIN_REALM}${process.env.REALM}${process.env.KEYCLOAK_USER_URL}`;
|
||||
const URL = urlcat(process.env.KEYCLOAK_HOST, URLPATH, { userid });
|
||||
const response = await fetch(URL, {
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
body: JSON.stringify(keycloakUser),
|
||||
});
|
||||
if (!response.ok) {
|
||||
throw new Error(`HTTP error! status: ${response.status}`);
|
||||
}
|
||||
}
|
||||
// public async getLastLogin(userid: string) {
|
||||
// const token = await this.getAccessToken();
|
||||
// const URLPATH = `${process.env.KEYCLOAK_ADMIN_REALM}${process.env.REALM}${process.env.KEYCLOAK_LASTLOGIN_URL}`;
|
||||
|
||||
Reference in New Issue
Block a user