Closed smokranova closed 1 year ago
@smokranova - Thanks for reporting your issue. We will check this at our end and will get back to you.
@smokranova - Please have look into this sample-https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-conversation-sso-quickstart/js/index.js#L34
const adapter = new CloudAdapter(botFrameworkAuthentication);
server.post('/api/messages', async (req, res) => {
// Route received a request to adapter for processing
await adapter.process(req, res, (context) => bot.run(context));
});
Also refer the document for the Cloud Adapter class-https://learn.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.integration.aspnet.core.cloudadapter?view=botbuilder-dotnet-stable
Hi, thanks for your answer. I have seen both of the things you linked while looking for an answer, however neither quite helps me with how to get the token or sign in link
@smokranova -Please have look into this sample- https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/f7779e42022176c3ae807e4e23acf0d0479c6c39/samples/app-complete-auth/csharp/AppCompleteAuth/Bots/ActivityBot.cs
Hope it is helpful.
protected override async Task<MessagingExtensionActionResponse> OnTeamsMessagingExtensionFetchTaskAsync(ITurnContext<IInvokeActivity> turnContext, MessagingExtensionAction action, CancellationToken cancellationToken)
{
if ((!string.IsNullOrEmpty(action.State) && action.CommandId.ToLower() == "sso") || action.CommandId.ToLower() == "sso")
{
var state = action.State; // Check the state value
var tokenResponse = await GetTokenResponse(turnContext, _botConnectionName, state, cancellationToken);
if (tokenResponse == null || string.IsNullOrEmpty(tokenResponse.Token))
{
// There is no token, so the user has not signed in yet.
// Retrieve the OAuth Sign in Link to use in the MessagingExtensionResult Suggested Actions
var signInLink = await GetSignInLinkAsync(turnContext, _botConnectionName, cancellationToken).ConfigureAwait(false);
return new MessagingExtensionActionResponse
{
ComposeExtension = new MessagingExtensionResult
{
Type = "auth",
SuggestedActions = new MessagingExtensionSuggestedAction
{
Actions = new List<CardAction>
{
new CardAction
{
Type = ActionTypes.OpenUrl,
Value = signInLink,
Title = "Bot Service OAuth",
},
},
},
},
};
}
I looked at what you sent and tried it (in nodejs no csharp, but same bot). I still get stuck at the signinlink. I see the SignIn button that is part of the Bot Service OAuth card, however after clicking it I get "Something went wrong, please try again". The sign in url is in the form of "https://europe.token.botframework.com/api/oauth/signin?signin=
@smokranova -Here is node sample-https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/f7779e42022176c3ae807e4e23acf0d0479c6c39/samples/app-complete-auth/nodejs
Also please have look into this document to add the authentication to teams bot-https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/authentication/add-authentication?tabs=dotnet%2Cdotnet-sample#prerequisites
Hi, my issue in the last bit ended up being that the valid domain in the manifest needed to be "europe.botframework...". now it all finally works, thanks!
In the following sample https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/app-sso/nodejs/server/bots/botActivityHandler.js it seems that the
context.adapter
should be of typeBotFrameworkAdapter
, however it appears to be of typeCloudAdapter
, which meansgetUserToken
andgetSignInLink
in the functionhandleTeamsMessagingExtensionFetchTask
throw an exception. Is there a version of these functions that works with CloudAdapter or a different way to authenticate within a message extension?