Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added token retrieve from user activate MAPI request #1158

Merged
merged 2 commits into from
Feb 19, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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