示例#1
0
        public async Task AuthorizeWithCodeAsync(string code)
        {
            var reqUri = UriUtils.GetUriWithQueryParameters("https://foursquare.com/oauth2/access_token", new Dictionary <string, string>()
            {
                { "client_id", this._clientInfo.ClientId },
                { "client_secret", this._clientInfo.ClientSecret },
                { "grant_type", "authorization_code" },
                { "redirect_uri", this._clientInfo.AuthorizationRedirectUri.ToString() },
                { "code", code }
            });

            using (var httpResponse = await this._httpClient.GetAsync(reqUri))
            {
                var responseJson = await httpResponse.Content.ReadAsStringAsync();

                if (httpResponse.StatusCode != System.Net.HttpStatusCode.OK)
                {
                    throw new SwarmServiceRestException(
                              "Authorize failured.", reqUri, httpResponse.StatusCode, responseJson, null);
                }

                try
                {
                    this.AccessToken = JsonConvert.DeserializeObject <UserAccessToken>(responseJson);
                }
                catch (Exception ex)
                {
                    throw new SwarmServiceJsonException(ex, responseJson);
                }
            }
        }
示例#2
0
        // 公開メソッド

        public Uri GetAuthorizationUri()
        {
            return(UriUtils.GetUriWithQueryParameters("https://foursquare.com/oauth2/authenticate", new Dictionary <string, string>()
            {
                { "client_id", this._clientInfo.ClientId },
                { "response_type", "code" },
                { "redirect_uri", this._clientInfo.AuthorizationRedirectUri.ToString() }
            }));
        }