|
| 1 | +using System.Threading; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Args = System.Collections.Generic.Dictionary<string, object>; |
| 4 | + |
| 5 | +namespace SlackNet.WebApi |
| 6 | +{ |
| 7 | + public interface IOpenIdApi |
| 8 | + { |
| 9 | + /// <summary> |
| 10 | + /// Exchanges a temporary OAuth verifier code for an access token for Sign in with Slack. |
| 11 | + /// See https://api.slack.com/methods/openid.connect.token for more information. |
| 12 | + /// </summary> |
| 13 | + /// <param name="clientId">Issued when you created your application.</param> |
| 14 | + /// <param name="clientSecret">Issued when you created your application.</param> |
| 15 | + /// <param name="code">The code param returned via the OAuth callback.</param> |
| 16 | + /// <param name="grantType">The grant_type param as described in the OAuth spec.</param> |
| 17 | + /// <param name="redirectUrl">This must match the originally submitted URI (if one was sent).</param> |
| 18 | + /// <param name="refreshToken">The refresh_token param as described in the OAuth spec.</param> |
| 19 | + /// <param name="cancellationToken"></param> |
| 20 | + Task<OpenIdTokenResponse> Token( |
| 21 | + string clientId, |
| 22 | + string clientSecret, |
| 23 | +#nullable enable |
| 24 | + string? code, |
| 25 | + string? grantType, |
| 26 | + string? redirectUrl, |
| 27 | + string? refreshToken, |
| 28 | +#nullable disable |
| 29 | + CancellationToken? cancellationToken |
| 30 | + ); |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// Get the identity of a user who has authorized Sign in with Slack. |
| 34 | + /// See https://api.slack.com/methods/openid.connect.userInfo for more information. |
| 35 | + /// Note: that this method uses an Authentication token passed in the header. |
| 36 | + /// Use <c>SlackApiClient.WithAccessToken</c> to specify a token. |
| 37 | + /// </summary> |
| 38 | + /// <param name="token">Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.</param> |
| 39 | + /// <param name="cancellationToken"></param> |
| 40 | + Task<OpenIdUserInfoResponse> UserInfo(CancellationToken? cancellationToken); |
| 41 | + |
| 42 | + } |
| 43 | + |
| 44 | + public class OpenIdApi : IOpenIdApi |
| 45 | + { |
| 46 | + private readonly ISlackApiClient _client; |
| 47 | + public OpenIdApi(ISlackApiClient client) => _client = client; |
| 48 | + |
| 49 | + /// <summary> |
| 50 | + /// Exchanges a temporary OAuth verifier code for an access token for Sign in with Slack. |
| 51 | + /// See https://api.slack.com/methods/openid.connect.token for more information. |
| 52 | + /// </summary> |
| 53 | + /// <param name="clientId">Issued when you created your application.</param> |
| 54 | + /// <param name="clientSecret">Issued when you created your application.</param> |
| 55 | + /// <param name="code">The code param returned via the OAuth callback.</param> |
| 56 | + /// <param name="grantType">The grant_type param as described in the OAuth spec.</param> |
| 57 | + /// <param name="redirectUrl">This must match the originally submitted URI (if one was sent).</param> |
| 58 | + /// <param name="refreshToken">The refresh_token param as described in the OAuth spec.</param> |
| 59 | + /// <param name="cancellationToken"></param> |
| 60 | + public Task<OpenIdTokenResponse> Token( |
| 61 | + string clientId, |
| 62 | + string clientSecret, |
| 63 | +#nullable enable |
| 64 | + string? code, |
| 65 | + string? grantType, |
| 66 | + string? redirectUrl, |
| 67 | + string? refreshToken, |
| 68 | +#nullable disable |
| 69 | + CancellationToken? cancellationToken = null |
| 70 | + ) => _client.Post<OpenIdTokenResponse>("openid.connect.token", new Args |
| 71 | + { |
| 72 | + { "client_id", clientId }, |
| 73 | + { "client_secret", clientSecret }, |
| 74 | + { "code", code }, |
| 75 | + { "grant_type", grantType }, |
| 76 | + { "redirect_uri", redirectUrl }, |
| 77 | + { "refresh_token", refreshToken } |
| 78 | + }, cancellationToken); |
| 79 | + |
| 80 | + |
| 81 | + /// <summary> |
| 82 | + /// Get the identity of a user who has authorized Sign in with Slack. |
| 83 | + /// See https://api.slack.com/methods/openid.connect.userInfo for more information. |
| 84 | + /// Note: that this method uses an Authentication token passed in the header. |
| 85 | + /// Use <c>SlackApiClient.WithAccessToken</c> to specify a token. |
| 86 | + /// </summary> |
| 87 | + /// <param name="token">Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.</param> |
| 88 | + /// <param name="cancellationToken"></param> |
| 89 | + public Task<OpenIdUserInfoResponse> UserInfo(CancellationToken? cancellationToken = null) => |
| 90 | + _client.Post<OpenIdUserInfoResponse>("openid.connect.userInfo", new Args { }, cancellationToken); |
| 91 | + } |
| 92 | +} |
0 commit comments