197 lines
No EOL
8.5 KiB
JavaScript
197 lines
No EOL
8.5 KiB
JavaScript
"use strict";
|
|
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT License.
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
});
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.UserTokenClientImpl = void 0;
|
|
const z = __importStar(require("zod"));
|
|
const tokenApiClient_1 = require("../tokenApi/tokenApiClient");
|
|
const userTokenClient_1 = require("./userTokenClient");
|
|
/**
|
|
* @internal
|
|
* Implementation of [UserTokenClient](xref:botframework-connector.UserTokenClient) for access user token service.
|
|
*/
|
|
class UserTokenClientImpl extends userTokenClient_1.UserTokenClient {
|
|
/**
|
|
* @param appId The appId.
|
|
* @param credentials AppCredentials for OAuth.
|
|
* @param oauthEndpoint The OAuth API endpoint.
|
|
* @param connectorClientOptions A ConnectorClientOptions object.
|
|
*/
|
|
constructor(appId, credentials, oauthEndpoint, connectorClientOptions = {}) {
|
|
super();
|
|
this.appId = appId;
|
|
this.client = new tokenApiClient_1.TokenApiClient(credentials, Object.assign({ baseUri: oauthEndpoint }, connectorClientOptions));
|
|
}
|
|
/**
|
|
* Attempts to retrieve the token for a user that's in a login flow.
|
|
*
|
|
* @param userId The user id that will be associated with the token.
|
|
* @param connectionName Name of the auth connection to use.
|
|
* @param channelId The channel Id that will be associated with the token.
|
|
* @param magicCode (Optional) Optional user entered code to validate.
|
|
* @returns The token Response.
|
|
*/
|
|
getUserToken(userId, connectionName, channelId, magicCode) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
userId: z.string(),
|
|
connectionName: z.string(),
|
|
channelId: z.string(),
|
|
}).parse({
|
|
userId,
|
|
connectionName,
|
|
channelId,
|
|
});
|
|
const result = yield this.client.userToken.getToken(userId, connectionName, { channelId, code: magicCode });
|
|
return result._response.parsedBody;
|
|
});
|
|
}
|
|
/**
|
|
* Asynchronously Get the raw signin resource to be sent to the user for signin.
|
|
*
|
|
* @param connectionName Name of the auth connection to use.
|
|
* @param activity The Activity from which to derive the token exchange state.
|
|
* @param finalRedirect The final URL that the OAuth flow will redirect to.
|
|
* @returns The [SignInUrlResponse](xref:botframework-schema.SignInUrlResponse) resource.
|
|
*/
|
|
getSignInResource(connectionName, activity, finalRedirect) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
activity: z.record(z.unknown()),
|
|
connectionName: z.string(),
|
|
}).parse({
|
|
activity,
|
|
connectionName,
|
|
});
|
|
const result = yield this.client.botSignIn.getSignInResource(userTokenClient_1.UserTokenClient.createTokenExchangeState(this.appId, connectionName, activity), { finalRedirect });
|
|
return result._response.parsedBody;
|
|
});
|
|
}
|
|
/**
|
|
* Signs the user out with the token server.
|
|
*
|
|
* @param userId The user id that will be associated with the token.
|
|
* @param connectionName Name of the auth connection to use.
|
|
* @param channelId The channel Id that will be associated with the token.
|
|
*/
|
|
signOutUser(userId, connectionName, channelId) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
userId: z.string(),
|
|
connectionName: z.string(),
|
|
channelId: z.string(),
|
|
}).parse({
|
|
userId,
|
|
connectionName,
|
|
channelId,
|
|
});
|
|
yield this.client.userToken.signOut(userId, { channelId, connectionName });
|
|
});
|
|
}
|
|
/**
|
|
* Retrieves the token status for each configured connection for the given user.
|
|
*
|
|
* @param userId The user id that will be associated with the token.
|
|
* @param channelId The channel Id that will be associated with the token.
|
|
* @param includeFilter The includeFilter.
|
|
* @returns A promise with an Array of the Token Status.
|
|
*/
|
|
getTokenStatus(userId, channelId, includeFilter) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
userId: z.string(),
|
|
channelId: z.string(),
|
|
}).parse({
|
|
userId,
|
|
channelId,
|
|
});
|
|
const result = yield this.client.userToken.getTokenStatus(userId, {
|
|
channelId,
|
|
include: includeFilter,
|
|
});
|
|
return result._response.parsedBody;
|
|
});
|
|
}
|
|
/**
|
|
* Retrieves Azure Active Directory tokens for particular resources on a configured connection.
|
|
*
|
|
* @param userId The user id that will be associated with the token.
|
|
* @param connectionName Name of the auth connection to use.
|
|
* @param resourceUrls The list of resource URLs to retrieve tokens for.
|
|
* @param channelId The channel Id that will be associated with the token.
|
|
* @returns A promise of Dictionary of resourceUrl to the corresponding TokenResponse.
|
|
*/
|
|
getAadTokens(userId, connectionName, resourceUrls, channelId) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
userId: z.string(),
|
|
connectionName: z.string(),
|
|
channelId: z.string(),
|
|
}).parse({
|
|
userId,
|
|
connectionName,
|
|
channelId,
|
|
});
|
|
const result = yield this.client.userToken.getAadTokens(userId, connectionName, { resourceUrls }, { channelId });
|
|
return result._response.parsedBody;
|
|
});
|
|
}
|
|
/**
|
|
* Performs a token exchange operation such as for single sign-on.
|
|
*
|
|
* @param userId The user id that will be associated with the token.
|
|
* @param connectionName Name of the auth connection to use.
|
|
* @param channelId The channel Id that will be associated with the token.
|
|
* @param exchangeRequest The exchange request details, either a token to exchange or a uri to exchange.
|
|
* @returns A promise representing the result of the operation.
|
|
*/
|
|
exchangeToken(userId, connectionName, channelId, exchangeRequest) {
|
|
return __awaiter(this, void 0, void 0, function* () {
|
|
z.object({
|
|
userId: z.string(),
|
|
connectionName: z.string(),
|
|
channelId: z.string(),
|
|
}).parse({
|
|
userId,
|
|
connectionName,
|
|
channelId,
|
|
});
|
|
const result = yield this.client.userToken.exchangeAsync(userId, connectionName, channelId, exchangeRequest);
|
|
return result._response.parsedBody;
|
|
});
|
|
}
|
|
}
|
|
exports.UserTokenClientImpl = UserTokenClientImpl;
|
|
//# sourceMappingURL=userTokenClientImpl.js.map
|