Skip to content

Commit

Permalink
Added token retrieve from user activate MAPI request (#1158)
Browse files Browse the repository at this point in the history
* Added token retrive from user activate MAPI request
close #1157
  • Loading branch information
ygrik committed Feb 19, 2021
1 parent 661544d commit c2e2b9b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/services/usersService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { KnownHttpHeaders } from "./../models/knownHttpHeaders";
import { AccessToken } from "./../authentication/accessToken";
import * as Constants from "./../constants";
import { Router } from "@paperbits/common/routing";
import { HttpHeader, HttpClient } from "@paperbits/common/http";
import { HttpHeader, HttpClient, HttpResponse } from "@paperbits/common/http";
import { ISettingsProvider } from "@paperbits/common/configuration";
import { IAuthenticator } from "../authentication";
import { MapiClient } from "./mapiClient";
Expand Down Expand Up @@ -100,7 +100,16 @@ export class UsersService {
const requestUrl = `/users/${userId}/identities/Basic/${identity}?appType=${Constants.AppType}`;
const token = `Ticket id="${ticketId}",ticket="${ticket}"`;

await this.mapiClient.put<void>(requestUrl, [{ name: "Authorization", value: token }, MapiClient.getPortalHeader("activateUser")]);
let managementApiUrl = await this.settingsProvider.getSetting<string>("managementApiUrl");
managementApiUrl = Utils.ensureUrlArmified(managementApiUrl);

const response = await this.httpClient.send({
url: `${managementApiUrl}${requestUrl}&api-version=${Constants.managementApiVersion}`,
method: "PUT",
headers: [{ name: "Authorization", value: token }, MapiClient.getPortalHeader("activateUser")]
});

await this.getTokenFromResponse(response);
}

public async updatePassword(userId: string, newPassword: string, token: string): Promise<void> {
Expand Down Expand Up @@ -308,6 +317,10 @@ export class UsersService {
body: JSON.stringify(user)
});

await this.getTokenFromResponse(response);
}

private async getTokenFromResponse(response: HttpResponse<any>) {
if (!(response.statusCode >= 200 && response.statusCode <= 299)) {
throw MapiError.fromResponse(response);
}
Expand Down

0 comments on commit c2e2b9b

Please sign in to comment.