Exemplo n.º 1
0
        public void OauthAccessTestsThrowsInvalidCodeOnInvalidCodes()
        {
            var oauthAccessRequest = new OauthAccessRequest
            {
                ClientId     = Environment.GetEnvironmentVariable("CLIENT_ID"),
                ClientSecret = Environment.GetEnvironmentVariable("CLIENT_SECRET"),
                Code         = ""
            };
            var ex = Assert.Throws <WellKnownSlackApiException>(() =>
            {
                var oAuthAccess = SlackOAuthClient.OAuthAccess(oauthAccessRequest).GetAwaiter().GetResult();
                return(oAuthAccess);
            });

            Assert.Equal("invalid_code", ex.Message);
        }
        /// <inheritdoc/>
        public async Task <OAuthAccessResponse> OAuthAccess(OauthAccessRequest oauthAccessRequest)
        {
            var parameters = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("client_id", oauthAccessRequest.ClientId),
                new KeyValuePair <string, string>("client_secret", oauthAccessRequest.ClientSecret),
                new KeyValuePair <string, string>("code", oauthAccessRequest.Code)
            };

            if (!string.IsNullOrEmpty(oauthAccessRequest.RedirectUri))
            {
                parameters.Add(new KeyValuePair <string, string>("redirect_uri", oauthAccessRequest.RedirectUri));
            }

            if (oauthAccessRequest.SingleChannel.HasValue)
            {
                parameters.Add(new KeyValuePair <string, string>("single_channel", oauthAccessRequest.SingleChannel.Value ? "true" : "false"));
            }

            return(await _client.PostParametersAsForm <OAuthAccessResponse>(parameters, "oauth.access", s => _logger?.LogTrace(s)));
        }