/// <summary> /// Returns URI of service which should be called in order to start authentication process. /// This URI should be used for rendering login link. /// </summary> /// <param name="state"> /// Any additional information that will be posted back by service. /// </param> /// <param name="cancellationToken"></param> public virtual Task <string> GetLoginLinkUriAsync(string state = null, CancellationToken cancellationToken = default) { var client = _factory.CreateClient(AccessCodeServiceEndpoint); var request = _factory.CreateRequest(AccessCodeServiceEndpoint); if (String.IsNullOrEmpty(Configuration.Scope)) { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, state }); } else { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, scope = Configuration.Scope, state }); } return(Task.FromResult(client.BuildUri(request).ToString())); }
/// <summary> /// Issues request for request token and returns result. /// </summary> /// <returns>The task the request token gets queried on</returns> private async Task QueryRequestToken() { var client = _factory.CreateClient(RequestTokenServiceEndpoint); client.Authenticator = OAuth1Authenticator.ForRequestToken( Configuration.ClientId, Configuration.ClientSecret, Configuration.RedirectUri); var request = _factory.CreateRequest(RequestTokenServiceEndpoint, Method.POST); BeforeGetAccessToken( new BeforeAfterRequestArgs { Client = client, Request = request, Configuration = Configuration }); var response = await client.ExecuteAndVerify(request).ConfigureAwait(false); AfterGetAccessToken( new BeforeAfterRequestArgs { Response = response, }); var collection = response.Content.ParseQueryString(); AccessToken = collection.GetOrThrowUnexpectedResponse(_oAuthTokenKey); AccessTokenSecret = collection.GetOrThrowUnexpectedResponse(_oAuthTokenSecretKey); }
/// <summary> /// Issues request for request token and returns result. /// </summary> private void QueryRequestToken() { var client = _factory.CreateClient(RequestTokenServiceEndpoint); client.Authenticator = OAuth1Authenticator.ForRequestToken( Configuration.ClientId, Configuration.ClientSecret, Configuration.RedirectUri); var request = _factory.CreateRequest(RequestTokenServiceEndpoint, Method.POST); BeforeGetAccessToken(new BeforeAfterRequestArgs { Client = client, Request = request, Configuration = Configuration }); var response = client.ExecuteAndVerify(request); AfterGetAccessToken(new BeforeAfterRequestArgs { Response = response, }); var collection = HttpUtility.ParseQueryString(response.Content); AccessToken = collection.GetOrThrowMissingValue(OAuthTokenKey); AccessTokenSecret = collection.GetOrThrowMissingValue(OAuthTokenSecretKey); }
/// <summary> /// Returns URI of service which should be called in order to start authentication process. /// This URI should be used for rendering login link. /// </summary> /// <param name="state">Any additional information that will be posted back by service.</param> /// <returns>A string containing the login link URI</returns> public virtual async Task <string> GetLoginLinkUri(string state = null) { var client = _factory.CreateClient(AccessCodeServiceEndpoint); var request = _factory.CreateRequest(AccessCodeServiceEndpoint); request.AddObject( new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, scope = Configuration.Scope, state }, new[] { (string.IsNullOrEmpty(Configuration.Scope) ? "scope" : null) }, PropertyFilterMode.Exclude); await BeforeGetLoginLinkUri( new BeforeAfterRequestArgs() { Client = client, Request = request, Configuration = Configuration, }); return(client.BuildUri(request).ToString()); }
/// <summary> /// Returns URI of service which should be called in order to start authentication process. /// This URI should be used for rendering login link. /// </summary> /// <param name="state"> /// Any additional information that will be posted back by service. /// </param> public virtual string GetLoginLinkUri(string state = null) { var client = _factory.CreateClient(AccessCodeServiceEndpoint); var request = _factory.CreateRequest(AccessCodeServiceEndpoint); if (String.IsNullOrEmpty(Configuration.Scope)) { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, state }); } else { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, scope = Configuration.Scope, state }); } return(client.BuildUri(request).ToString()); }
/// <summary> /// Issues request for request token and returns result. /// </summary> private void QueryRequestToken() { var client = _factory.CreateClient(RequestTokenServiceEndpoint); client.Authenticator = OAuth1Authenticator.ForRequestToken( Configuration.ClientId, Configuration.ClientSecret, Configuration.RedirectUri); var request = _factory.CreateRequest(RequestTokenServiceEndpoint, Method.POST); var response = client.ExecuteAndVerify(request); var collection = HttpUtility.ParseQueryString(response.Content); AccessToken = collection.GetOrThrowUnexpectedResponse(OAuthTokenKey); AccessTokenSecret = collection.GetOrThrowUnexpectedResponse(OAuthTokenSecretKey); }
public void SetUp() { requestFactory = Substitute.For<IRequestFactory>(); requestFactory.CreateClient().Execute(requestFactory.CreateRequest()).StatusCode = HttpStatusCode.OK; descendant = new FacebookClientDescendant( requestFactory, Substitute.For<IClientConfiguration>()); }
public void SetUp() { _requestFactory = Substitute.For <IRequestFactory>(); _requestFactory.CreateClient().Execute(_requestFactory.CreateRequest()).StatusCode = HttpStatusCode.OK; _descendant = new DigitalOceanClientDescendant( _requestFactory, Substitute.For <IClientConfiguration>()); }
public void SetUp() { requestFactory = Substitute.For<IRequestFactory>(); requestFactory.CreateClient().Execute(requestFactory.CreateRequest()).StatusCode = HttpStatusCode.OK; descendant = new DigitalOceanClientDescendant( requestFactory, Substitute.For<IClientConfiguration>()); }
public void SetUp() { factory = Substitute.For<IRequestFactory>(); factory.CreateClient().Execute(factory.CreateRequest()).StatusCode = HttpStatusCode.OK; descendant = new OAuthClientDescendant( factory, Substitute.For<IClientConfiguration>()); }
public static HttpClient CreateClient(this IRequestFactory factory, EndPoint endpoint, AuthenticationHeaderValue auth) { var client = factory.CreateClient(auth); client.BaseAddress = new Uri(endpoint.BaseUri); return(client); }
public static IRestClient CreateClient(this IRequestFactory factory, Endpoint endpoint) { var client = factory.CreateClient(); client.BaseUrl = endpoint.BaseUri; return(client); }
public AddressSearchService(IRequestFactory requestFactory) { if (requestFactory == null) { throw new ArgumentNullException(nameof(requestFactory)); } _client = requestFactory.CreateClient(); }
/// <summary> /// Get User Profile Infor from Yahoo Api /// https://social.yahooapis.com/v1/user/{UserProfileGUID}/profile?format=json /// </summary> /// <returns></returns> protected async Task <UserInfo> GetUserInfo() { string url = string.Format(AuthApiEndPoints.UserInfoServiceEndpoint.Resource, UserProfileGUID); var tempEndPoint = new EndPoint { BaseUri = AuthApiEndPoints.UserInfoServiceEndpoint.BaseUri, Resource = url }; var client = _factory.CreateClient(tempEndPoint, new AuthenticationHeaderValue("Bearer", Auth.AccessToken)); var request = _factory.CreateRequest(tempEndPoint); var response = await client.GetAsync(request.RequestUri); var result = await response.Content.ReadAsStringAsync(); var userInfo = JsonConvert.DeserializeObject <UserInfo>(result); return(userInfo); }
public void SetUp() { factory = Substitute.For<IRequestFactory>(); var client = Substitute.For<IRestClient>(); var request = Substitute.For<IRestRequest>(); var response = Substitute.For<IRestResponse>(); factory.CreateClient().Returns(client); factory.CreateRequest(null).ReturnsForAnyArgs(request); client.Execute(request).Returns(Task.FromResult(response)); response.StatusCode.Returns(HttpStatusCode.OK); descendant = new VkClientDescendant(factory, Substitute.For<IClientConfiguration>()); }
public void SetUp() { factory = Substitute.For <IRequestFactory>(); var client = Substitute.For <IRestClient>(); var request = Substitute.For <IRestRequest>(); var response = Substitute.For <IRestResponse>(); factory.CreateClient().Returns(client); factory.CreateRequest(null).ReturnsForAnyArgs(request); client.Execute(request).Returns(Task.FromResult(response)); response.StatusCode.Returns(HttpStatusCode.OK); descendant = new VkClientDescendant(factory, Substitute.For <IClientConfiguration>()); }
/// <summary> /// Returns URI of service which should be called in order to start authentication process. /// This URI should be used for rendering login link. /// </summary> /// <param name="state"> /// Any additional information that will be posted back by service. /// </param> /// <param name="cancellationToken"></param> /// <param name="queryParameters">Additional query parameters</param> public virtual Task <string> GetLoginLinkUriAsync(string state = null, CancellationToken cancellationToken = default, NameValueCollection queryParameters = null) { var client = _factory.CreateClient(AccessCodeServiceEndpoint); var request = _factory.CreateRequest(AccessCodeServiceEndpoint); if (String.IsNullOrEmpty(Configuration.Scope)) { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, state }); } else { request.AddObject(new { response_type = "code", client_id = Configuration.ClientId, redirect_uri = Configuration.RedirectUri, scope = Configuration.Scope, state }); } if (queryParameters != null) { foreach (string queryParameterKey in queryParameters.AllKeys) { request.AddQueryParameter(queryParameterKey, queryParameters[queryParameterKey]); } } return(Task.FromResult(client.BuildUri(request).ToString())); }
public void SetUp() { _restRequest = Substitute.For <IRestRequest>(); _restResponse = Substitute.For <IRestResponse>(); _restResponse.StatusCode.Returns(HttpStatusCode.OK); _restResponse.Content.Returns("response"); _restClient = Substitute.For <IRestClient>(); _restClient.ExecuteAsync(_restRequest, CancellationToken.None).Returns(_restResponse); _factory = Substitute.For <IRequestFactory>(); _factory.CreateClient().Returns(_restClient); _factory.CreateRequest().Returns(_restRequest); _descendant = new FacebookClientDescendant(_factory, Substitute.For <IClientConfiguration>()); }
public static string GetToken(HttpContext context) { mFactory = new RequestFactory(); var request = mFactory.CreateRequest(); request.Resource = "/oauth/authorize"; ConfigVars.Instance.RedirectUri = string.Format("http://localhost:{0}/login/oauthcallback", context.Request.Host.Port); request.AddObject(new { response_type = "code", client_id = ConfigVars.Instance.ClientId, redirect_uri = ConfigVars.Instance.RedirectUri, }); var client = mFactory.CreateClient(); client.BaseUrl = ConfigVars.Instance.AuthServerBaseUrl; return(client.BuildUri(request).ToString()); }
protected override UserInfo GetUserInfo() { var client = _factory.CreateClient(UserInfoServiceEndpoint); //client.Authenticator = new OAuth2UriQueryParameterAuthenticator(AccessToken); client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(AccessToken, "Bearer"); var request = _factory.CreateRequest(UserInfoServiceEndpoint); BeforeGetUserInfo(new BeforeAfterRequestArgs { Client = client, Request = request, Configuration = Configuration }); var response = client.ExecuteAndVerify(request); var result = ParseUserInfo(response.Content); result.ProviderName = Name; return(result); }
public void SetUp() { _restRequest = Substitute.For <IRestRequest>(); _restResponse = Substitute.For <IRestResponse>(); _restResponse.StatusCode.Returns(HttpStatusCode.OK); _restResponse.Content.Returns("response"); _restClient = Substitute.For <IRestClient>(); _restClient.ExecuteTaskAsync(_restRequest, CancellationToken.None).Returns(_restResponse); _factory = Substitute.For <IRequestFactory>(); _factory.CreateClient().Returns(_restClient); _factory.CreateRequest().Returns(_restRequest); var configuration = Substitute.For <IClientConfiguration>(); configuration.ClientId.Returns("client_id"); configuration.ClientSecret.Returns("client_secret"); configuration.RedirectUri.Returns("http://redirect-uri.net"); configuration.Scope.Returns("scope"); _descendant = new OAuth2ClientDescendant(_factory, configuration); }
public void SetUp() { restRequest = Substitute.For<IRestRequest>(); restResponse = Substitute.For<IRestResponse>(); restResponse.StatusCode.Returns(HttpStatusCode.OK); restResponse.Content.Returns("response"); restClient = Substitute.For<IRestClient>(); restClient.Execute(restRequest).Returns(restResponse); factory = Substitute.For<IRequestFactory>(); factory.CreateClient().Returns(restClient); factory.CreateRequest().Returns(restRequest); var configuration = Substitute.For<IClientConfiguration>(); configuration.ClientId.Returns("client_id"); configuration.ClientSecret.Returns("client_secret"); configuration.RedirectUri.Returns("http://redirect-uri.net"); configuration.Scope.Returns("scope"); descendant = new OAuth2ClientDescendant(factory, configuration); }
public void SetUp() { restRequest = Substitute.For <IRestRequest>(); restResponse = Substitute.For <IRestResponse>(); restResponse.StatusCode.Returns(HttpStatusCode.OK); restResponse.RawBytes.Returns(_encoding.GetBytes("response")); restClient = Substitute.For <IRestClient>(); restClient.Execute(restRequest).Returns(Task.FromResult(restResponse)); factory = Substitute.For <IRequestFactory>(); factory.CreateClient().Returns(restClient); factory.CreateRequest(null).ReturnsForAnyArgs(restRequest); var configuration = Substitute.For <IClientConfiguration>(); configuration.ClientId.Returns("client_id"); configuration.ClientSecret.Returns("client_secret"); configuration.RedirectUri.Returns("http://redirect-uri.net"); configuration.Scope.Returns("scope"); descendant = new OAuth2ClientDescendant(factory, configuration); }
public static HttpClient CreateClient(this IRequestFactory factory, AuthenticationHeaderValue auth) { var client = factory.CreateClient(auth); return(client); }