File

src/outbound/auth-api/auth-api.service.ts

Index

Methods

Constructor

constructor(httpService: HttpService)
Parameters :
Name Type Optional
httpService HttpService No

Methods

Async createSecret
createSecret(name: string, realmClient: string, token: string)
Parameters :
Name Type Optional
name string No
realmClient string No
token string No
Returns : Promise<void>
Async deleteCredential
deleteCredential(credentialId: string, realmClient: string, token: string)
Parameters :
Name Type Optional
credentialId string No
realmClient string No
token string No
Returns : unknown
Async getRealms
getRealms()
Returns : Promise<any>
Async postRealms
postRealms(body: literal type)
Parameters :
Name Type Optional
body literal type No
Returns : Promise<any>
Async putRealm
putRealm(realm: string, body: literal type)
Parameters :
Name Type Optional
realm string No
body literal type No
Returns : Promise<any>
Private Async returnToken
returnToken()
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();
  }
}

results matching ""

    No results matching ""