microsoft/teams.net
Publicmirrored fromhttps://github.com/microsoft/teams.netAvailable
Libraries/Microsoft.Teams.Api/Auth/TokenCredentials.cs
33lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT License. |
| 3 | |
| 4 | using Microsoft.Teams.Common.Http; |
| 5 | |
| 6 | namespace Microsoft.Teams.Api.Auth; |
| 7 | |
| 8 | public delegate Task<ITokenResponse> TokenFactory(string? tenantId, params string[] scopes); |
| 9 | |
| 10 | public class TokenCredentials : IHttpCredentials |
| 11 | { |
| 12 | public string ClientId { get; set; } |
| 13 | public string? TenantId { get; set; } |
| 14 | public TokenFactory Token { get; set; } |
| 15 | |
| 16 | public TokenCredentials(string clientId, TokenFactory token) |
| 17 | { |
| 18 | ClientId = clientId; |
| 19 | Token = token; |
| 20 | } |
| 21 | |
| 22 | public TokenCredentials(string clientId, string tenantId, TokenFactory token) |
| 23 | { |
| 24 | ClientId = clientId; |
| 25 | TenantId = tenantId; |
| 26 | Token = token; |
| 27 | } |
| 28 | |
| 29 | public async Task<ITokenResponse> Resolve(IHttpClient _client, string[] scopes, CancellationToken cancellationToken = default) |
| 30 | { |
| 31 | return await Token(TenantId, scopes); |
| 32 | } |
| 33 | } |