microsoft/teams.net

Public

mirrored fromhttps://github.com/microsoft/teams.netAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
fix/msal-cache

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

Libraries/Microsoft.Teams.Api/Clients/BotSignInClient.cs

71lines · modecode

1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT License.
3
4using Microsoft.Teams.Common.Http;
5
6namespace Microsoft.Teams.Api.Clients;
7
8public class BotSignInClient : Client
9{
10 public string TokenServiceUrl { get; set; } = "https://token.botframework.com";
11
12 public BotSignInClient() : base()
13 {
14
15 }
16
17 public BotSignInClient(IHttpClient client, CancellationToken cancellationToken = default) : base(client, cancellationToken)
18 {
19
20 }
21
22 public BotSignInClient(IHttpClientOptions options, CancellationToken cancellationToken = default) : base(options, cancellationToken)
23 {
24
25 }
26
27 public BotSignInClient(IHttpClientFactory factory, CancellationToken cancellationToken = default) : base(factory, cancellationToken)
28 {
29
30 }
31
32 public async Task<string> GetUrlAsync(GetUrlRequest request, CancellationToken cancellationToken = default)
33 {
34 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
35 var query = QueryString.Serialize(request);
36 var req = HttpRequest.Get(
37 $"{TokenServiceUrl}/api/botsignin/GetSignInUrl?{query}"
38 );
39
40 var res = await _http.SendAsync(req, token).ConfigureAwait(false);
41 return res.Body;
42 }
43
44 public async Task<SignIn.UrlResponse> GetResourceAsync(GetResourceRequest request, CancellationToken cancellationToken = default)
45 {
46 var token = cancellationToken != default ? cancellationToken : _cancellationToken;
47 var query = QueryString.Serialize(request);
48 var req = HttpRequest.Get(
49 $"{TokenServiceUrl}/api/botsignin/GetSignInResource?{query}"
50 );
51
52 var res = await _http.SendAsync<SignIn.UrlResponse>(req, token).ConfigureAwait(false);
53 return res.Body;
54 }
55
56 public class GetUrlRequest
57 {
58 public required string State { get; set; }
59 public string? CodeChallenge { get; set; }
60 public string? EmulatorUrl { get; set; }
61 public string? FinalRedirect { get; set; }
62 }
63
64 public class GetResourceRequest
65 {
66 public required string State { get; set; }
67 public string? CodeChallenge { get; set; }
68 public string? EmulatorUrl { get; set; }
69 public string? FinalRedirect { get; set; }
70 }
71}