src/outbound/auth-api/auth-api.service.ts
Methods |
|
constructor(httpService: HttpService)
|
||||||
Defined in src/outbound/auth-api/auth-api.service.ts:6
|
||||||
Parameters :
|
Async createSecret |
createSecret(name: string, realmClient: string, token: string)
|
Defined in src/outbound/auth-api/auth-api.service.ts:61
|
Returns :
Promise<void>
|
Async deleteCredential |
deleteCredential(credentialId: string, realmClient: string, token: string)
|
Defined in src/outbound/auth-api/auth-api.service.ts:84
|
Returns :
unknown
|
Async getRealms |
getRealms()
|
Defined in src/outbound/auth-api/auth-api.service.ts:16
|
Returns :
Promise<any>
|
Async postRealms | ||||||
postRealms(body: literal type)
|
||||||
Defined in src/outbound/auth-api/auth-api.service.ts:29
|
||||||
Parameters :
Returns :
Promise<any>
|
Async putRealm | |||||||||
putRealm(realm: string, body: literal type)
|
|||||||||
Defined in src/outbound/auth-api/auth-api.service.ts:45
|
|||||||||
Parameters :
Returns :
Promise<any>
|
Private Async returnToken |
returnToken()
|
Defined in src/outbound/auth-api/auth-api.service.ts:9
|
Returns :
Promise<any>
|
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { configENV } from '../../../config-env';
const { userRelms, passwordRelms, urlGetToken } = configENV;
@Injectable()
export class AuthApiService {
constructor(private readonly httpService: HttpService) {}
private async returnToken(): Promise<any> {
return await this.httpService.axiosRef.post(`${urlGetToken}/login`, {
username: userRelms,
password: passwordRelms,
});
}
async getRealms(): Promise<any> {
const { data } = await this.returnToken();
const res = await this.httpService.axiosRef.get(
`${urlGetToken}/api/realm/mtrix/admin/realm`,
{
headers: {
Authorization: 'Bearer ' + data.token,
},
},
);
return res.data;
}
async postRealms(body: { realm: string }): Promise<any> {
const { data } = await this.returnToken();
const res = await this.httpService.axiosRef
.post(`${urlGetToken}/api/realm/mtrix/admin/realm`, body, {
headers: {
Authorization: 'Bearer ' + data.token,
},
})
.then((data) => {
return data.data;
})
.catch();
return res;
}
async putRealm(realm: string, body: { enabled: boolean }): Promise<any> {
const { data } = await this.returnToken();
const res = await this.httpService.axiosRef
.put(`${urlGetToken}/api/realm/mtrix/admin/realm/${realm}`, body, {
headers: {
Authorization: 'Bearer ' + data.token,
},
})
.then((data) => {
return data.data;
})
.catch();
return res;
}
async createSecret(
name: string,
realmClient: string,
token: string,
): Promise<void> {
const res = await this.httpService.axiosRef
.post(
`${urlGetToken}/api/realm/mtrix/admin/client/${realmClient}/${name}`,
undefined,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
)
.then((data) => {
return data.data;
})
.catch();
return res;
}
async deleteCredential(
credentialId: string,
realmClient: string,
token: string,
) {
return await this.httpService.axiosRef
.delete(
`${urlGetToken}/api/realm/mtrix/admin/client/${realmClient}/${credentialId}`,
{
headers: {
Authorization: `Bearer ${token}`,
},
},
)
.then((data) => {
return data.data;
})
.catch();
}
}