private async promptForProvider()

in sdk/typescript/libraries/bot-solutions/src/authentication/multiProviderAuthDialog.ts [117:183]


    private async promptForProvider(stepContext: WaterfallStepContext): Promise<DialogTurnResult> {
        if (this.authenticationConnections.length === 1) {
            const result: string = this.authenticationConnections[0].name + '_' + stepContext.context.activity.locale.split('-')[0];

            return await stepContext.next(result);
        }

        //PENDING: adapter could not be parsed to IExtendedUserTokenProvider as C# does
        const adapter: BotFrameworkAdapter = stepContext.context.adapter as BotFrameworkAdapter;
        if (adapter !== undefined) {
            const tokenStatusCollection: TokenStatus[] = await adapter.getTokenStatus(
                stepContext.context,
                stepContext.context.activity.from.id,
                undefined,
                this.oauthCredentials);

            const matchingProviders: TokenStatus[] = tokenStatusCollection.filter((p: TokenStatus): boolean => {
                return (p.hasToken || false) && this.authenticationConnections.some((t: IOAuthConnection): boolean => {
                    return t.name === p.connectionName;
                });
            });

            if (matchingProviders.length === 1) {
                const authType: string|undefined = matchingProviders[0].connectionName;

                return stepContext.next(authType);
            }

            if (matchingProviders.length > 1) {
                const choices: Choice[] = matchingProviders.map((connection: TokenStatus): Choice => {
                    const value: string = connection.connectionName || '';

                    return {
                        action: {
                            type: ActionTypes.ImBack,
                            title: value,
                            value: value
                        },
                        value: value
                    };
                });

                return stepContext.prompt(DialogIds.providerPrompt, {
                    prompt: this.responseManager.getResponse(AuthenticationResponses.configuredAuthProvidersPrompt, stepContext.context.activity.locale as string),
                    choices: choices
                });
            } else {
                const choices: Choice[] = this.authenticationConnections.map((connection: IOAuthConnection): Choice => {
                    return {
                        action: {
                            type: ActionTypes.ImBack,
                            title: connection.name,
                            value: connection.name
                        },
                        value: connection.name
                    };
                });

                return stepContext.prompt(DialogIds.providerPrompt, {
                    prompt: this.responseManager.getResponse(AuthenticationResponses.authProvidersPrompt, stepContext.context.activity.locale as string),
                    choices: choices
                });
            }
        }

        throw new Error('The adapter doesn\'t support Token Handling.');
    }