in packages/app/main/src/server/utils/oauthLinkEncoder.ts [63:95]
public async resolveOAuthCards(activity: Activity): Promise<boolean> {
if (
this.conversationId &&
activity &&
activity.attachments &&
activity.attachments.length === 1 &&
activity.attachments[0].contentType === AttachmentContentTypes.oAuthCard
) {
const codeChallenge = this.generateCodeVerifier(this.conversationId);
const attachment: Attachment = activity.attachments[0] as Attachment;
const oauthCard: OAuthCard = attachment.content as OAuthCard;
if (oauthCard.buttons && oauthCard.buttons.length === 1) {
const cardAction = oauthCard.buttons[0];
if (cardAction.type === 'signin' && !cardAction.value) {
// generate a sign-in link for the oauth card and assign it to the button
try {
const link = await this.getSignInLink(oauthCard.connectionName, codeChallenge);
cardAction.value = link;
cardAction.type = 'openUrl';
} catch (e) {
// failed to generate a sign-in link, fall back to an emulated sign-in token
const link =
SharedConstants.EmulatedOAuthUrlProtocol + '//' + oauthCard.connectionName + '&&&' + this.conversationId;
cardAction.value = link;
cardAction.type = 'openUrl';
throw new Error(`Failed to generate an actual sign-in link: ${e}`);
}
}
}
}
return true;
}