Comments (5)
As suggested, adding in the getSsoToken function made all the difference and now I can query my API with no issues! :)
@JerryYangKai and @blackchoey thank you both for the great help! π π
from teams-toolkit.
Hi @FredTheDane , can you share how do you get the authentication token retrieved from Teams inside the tab
you mentioned? By the way, does the internal Web API
mean an API implemented in same project as your tab app? Or it means another web API project?
By default, the TeamsFx extension configured the web api to accept token got from Teams Tab single sign-on feature (you can use TeamsUserCredential to get such a token). You can find related configuration code at https://github.com/OfficeDev/TeamsFx/blob/dev/packages/simpleauth/src/TeamsFxSimpleAuth/SimpleAuthWebApiExtension.cs#L39-L55
from teams-toolkit.
Hi @blackchoey :)
The way that I try and use the Teams Authentication token is something along the lines of this inside the OnAfterRenderAsync method of the tab.razor file (The application is pretty much as is with what you get using the Microsoft Teams App project template:
var token = await teamsfx.GetAuthenticationToken();
WebClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + token.Token);
var value = await WebClient.GetAsync("https://localhost:44357/api/Diagram");
The Diagram api is just a quick and dirty API controller that spits out an array within the same project as the tab app. However, when checking the value I get this Unauthorized error back: {Bearer error="invalid_token", error_description="The signature is invalid"}
When you say that I can use TeamUserCredential to get a token, where would I need to implement this in the JwtBearerOptions and how would I get the token?
from teams-toolkit.
Thank you @FredTheDane for the details. The project created by Teams Toolkit extension wraps the TeamsUserCredential to acquire token. @JerryYangKai will provide more instructions on how to update the code to call the internal web APIs.
from teams-toolkit.
Hi @FredTheDane, since we only got JavaScript version of microsoft/teamsfx sdk, so we including webpack to wrapper it and using JSRuntime to trigger it in Blazor.
The webpack source code is in JS/src/index.js, you could add these code to get SSO token
export async function getSsoToken() {
var credential = new TeamsUserCredential();
var token = await credential.getToken("");
return token;
}
Then under JS folder , run 'npm install' and 'npm run build' to webpack the code and refresh the webpack file (wwwroot/teamsfx.js).
Finally you could using JSRuntime trigger the new func you just added in TeamsFx.cs.
await jsRuntime.InvokeAsync<AccessToken>("TeamsFx.getSsoToken");
We've tried to remove webpack and provide a more convenient way to using sdk in the future.
from teams-toolkit.
Related Issues (20)
- [Known Issue] Calling Azure Function will return ERR_CONNECTION_REFUSED. SSO projects with OBO flow can't popup login page. HOT 1
- Teams Toolkit => Prepare Teams App Dependencies throws "The operation has timed out." SystemError HOT 8
- bug report: custom-copilot-rag-custom-api.failed-to-update-custom-api-template HOT 2
- commandMiddleware converting all inputs to lowerCase, breaking some command scenarios HOT 3
- Possible "This app cannot be found" error when debugging a new Teams app HOT 1
- Cannot create new Teams apps with Teams Toolkit in Visual Studio Community 17.10.2 HOT 7
- Implementation of Translation in Teams Bot adaptive cards HOT 9
- The wrong dev tunnel is being selected HOT 4
- There was a problem reaching this app HOT 2
- Code Error HOT 2
- Teams Toolkit VS 2022 - .gitignore missing in TeamsApp.ttkproj HOT 2
- Teams tab app error - CP.UiRequiredError: Failed to get access token cache silently, please login first: you need login first before get access token. HOT 2
- Add skip update parameter to publishAppPackage if app exist HOT 1
- [Known Issue] VS local debug to open the Teams browser will use edge profile account instead of the project's m365 account HOT 1
- Teams app updates does not reflect quickly HOT 4
- (Γ) Error: teamsApp/extendToM365 failed. (Γ) Error: Request failed with status code 406 (tracingId: ) NotAcceptable: Error with the data stored in cache. This is most likely due to an error with the package being uploaded HOT 2
- Unable to create the bot through `teamsapp provision` HOT 3
- teamsApp/extendToM365 error with NotImplementedError HOT 4
- Reload cachΓ© in Microsoft Teams Tab HOT 3
- What is the purpose of creating an AAD application? HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. πππ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from teams-toolkit.