I’m working on a Teams tab app that will only be installed on a Teams Channel. At the present time, the app is not using SSO since the user will already be logged into Teams and be a member of the channel.
Upon request initiated by the user(s), the app will retrieve a file (byte[]
) via a REST API call. My goal is to then save that file into the folder in SharePoint that is defined by the TeamsChannelContext.RelativeUrl
. By all indications, from reading thru hundreds of articles, I need to use MS Graph to do this.
The main issue I’m having is finding a way to get a valid access token. Just about every article shows code using a clientId
(which I assume is either from the TeamsUserContext.Id
or perhaps the TeamsChannelContext.Id
) and either a client password or client secret, neither of which are available.
After several failed iterations trying to use CredentialCache.DefaultCredentials
in a web request, I found an article referring to creating a TokenProvider like…
public class TokenProvider : IAccessTokenProvider
{
public string token { get; set; }
public Task<string> GetAuthorizationTokenAsync(Uri uri, Dictionary<string, object> additionalAuthenticationContext = default,
CancellationToken cancellationToken = default)
{
return Task.FromResult(token);
}
public AllowedHostsValidator AllowedHostsValidator { get; }
}
…and called with…
TokenProvider provider = new TokenProvider();
TokenRequestContext ctx = new TokenRequestContext(new string[] { "User.ReadWrite.All" }, context.User.Id);
I tried to fill the ‘token’ string by creating a Microsoft.TeamsFx.TeamsUserCredential
, but could not get the ‘service’ setup for it in Program.cs
.
Is what I’m looking to do even possible ?