public void FromString_WithTwoGetParameters_ReturnsParameters() { var stringUrl = $"http://test/test.csproj?key=value&key2=value2"; var result = RequestUrl.FromString(stringUrl); var parameterResult = result.Parameters.Skip(1).Single(); Assert.AreEqual("key2", parameterResult.Key); Assert.AreEqual("value2", parameterResult.Value); }
/// <summary> /// 得到请求地址不包含域 /// 格式:/api/user?参数1=参数值&参数2=参数值 /// </summary> /// <param name="isSort">是否排序</param> /// <param name="isUrlEncode">是否url编码</param> /// <param name="encoding">编码格式,默认UTF8</param> /// <returns></returns> public string GetQueryPath(bool isSort = false, bool isUrlEncode = false, Encoding encoding = null) { var queryParam = GetQueryResult(isSort, isUrlEncode, encoding); if (!string.IsNullOrEmpty(queryParam)) { return($"{RequestUrl.Replace(Scheme + "://" + Host, "")}?{queryParam}"); } return($"{RequestUrl.Replace(Scheme + "://" + Host, "")}"); }
public async Task <ArticlesPaginated> GetArticlesAsync(int pageIndex, int pageSize = 5) { var requestUrl = new RequestUrl(_settingsService.ArticlesEndpoint); var dictionary = new Dictionary <string, string> { { "pageIndex", pageIndex.ToString() }, { "pageSize", pageSize.ToString() } }; return(await _requestProvider.GetAsync <ArticlesPaginated>(requestUrl.Create(dictionary))); }
public ResponseInfo <ResponseUrl> GetSODetails([FromBody] RequestUrl data) { try { return(base.PostDataToAPINotAuth <ResponseInfo <ResponseUrl> >(base.apiPathAndQuery, data)); } catch (Exception ex) { throw ex; } }
public RequestUrl GetWithAddRequestUrl(RequestUrl requestUrl) { using (var dbConnection = GetLoggingConnection()) { return(dbConnection.QuerySingleOrDefault <RequestUrl>("dbo.RequestUrl_GetWithAdd", new { RequestUrl = requestUrl.Url, }, commandType: CommandType.StoredProcedure)); } }
public LongUri(RequestUrl requestUrl) { _requestUrl = requestUrl; if (!_requestUrl.MultiUrl) { _requestUrl.UrlList = new List <string> { _requestUrl.UrlSingle } } ; _responseUrl = new ResponseUrl(); }
public byte[] ProcessRequest(RequestUrl url) { var requestedLocalFile = url.Resource.Replace('/', '\\'); if (requestedLocalFile == string.Empty) { requestedLocalFile = "index.html"; } var bytes = File.ReadAllBytes(Path.Combine(webAppDirectory, requestedLocalFile)); return(bytes); }
public async Task <List <CommentResponse> > GetCommentsAsync(int id, bool isArticle = true) { var requestUrl = new RequestUrl(_settingsService.CommentsEndpoint + "/" + id); var dic = new Dictionary <string, string> { { "isArticle", isArticle.ToString() } }; var url = requestUrl.Create(dic); var comments = await _requestProvider.GetAsync <List <CommentResponse> >(url); return(comments); }
public void ToString_WithPathAndParameters_ReturnsRequest() { var api = "testApi"; var resource = "test/csproj.csproj"; var parameter1 = new RequestParameter("key1", "value1"); var parameter2 = new RequestParameter("key2", "value2"); var testee = new RequestUrl(api, resource, new[] { parameter1, parameter2 }); var result = testee.ToString(); Assert.AreEqual("http://testApi/test/csproj.csproj?key1=value1&key2=value2", result); }
public async Task anonymous_user_should_be_redirected_to_login_page() { var url = new RequestUrl("https://server/subpath/connect/authorize").CreateAuthorizeUrl( clientId: "client1", responseType: "id_token", scope: "openid", redirectUri: "https://client1/callback", state: "123_state", nonce: "123_nonce"); var response = await _mockPipeline.BrowserClient.GetAsync(url); _mockPipeline.LoginWasCalled.Should().BeTrue(); }
/// <summary> /// Gets the token. /// </summary> /// <returns>System.String.</returns> public string GetToken() { var xeroAuthorizeUri = new RequestUrl(XeroUrl.IdentityServerAuthorize); var url = xeroAuthorizeUri.CreateAuthorizeUrl( clientId: _settings.ClientId, responseType: "code", //hardcoded authorisation code for now. redirectUri: "https://localhost:5001/oauth", state: "", scope: "openid profile email files accounting.transactions accounting.transactions.read accounting.reports.read accounting.journals.read accounting.settings accounting.settings.read accounting.contacts accounting.contacts.read accounting.attachments accounting.attachments.read offline_access" ); return(url); }
private string GetLoginUrl(string redirectUrl, string nonce, string state) { var config = GetOpenIdConnectConfiguration(); var requestUrl = new RequestUrl(config.AuthorizationEndpoint); return(requestUrl.CreateAuthorizeUrl(GetAttributeValue(AttributeKey.ApplicationId), OidcConstants.ResponseTypes.Code, GetScopes(), $"{redirectUrl}", state, nonce)); }
protected string GetAuthenticationURL() { var ru = new RequestUrl($"http://{Backend.BASE_URL}/connect/authorize"); var url = ru.CreateAuthorizeUrl( clientId: "clientApp", responseType: "code id_token", redirectUri: "https://localhost/signin-oidc", nonce: "xyz", scope: "openid offline_access profile resourceApi"); return(url); }
public void OnGet() { var xeroAuthorizeUri = new RequestUrl("https://login.xero.com/identity/connect/authorize"); var url = xeroAuthorizeUri.CreateAuthorizeUrl( clientId: GlobalConstant.ClientId, responseType: "code", //hardcoded authorisation code for now. redirectUri: GlobalConstant.RedirectUrl, state: "your state", scope: "openid profile email files accounting.transactions accounting.transactions.read accounting.reports.read accounting.journals.read accounting.settings accounting.settings.read accounting.contacts accounting.contacts.read accounting.attachments accounting.attachments.read offline_access" ); ViewData["XeroAuthorizeUrl"] = url; }
public JsonResult Shorten([FromBody] RequestUrl obj) { if (obj.Url != null) { if (CheckUrl(obj.Url)) { string hash; DateTime start = DateTime.Today; DateTime end = DateTime.Today; if (obj.AdvancedSettings?.Name == null) { do { hash = GetHashedUrl(obj.Url); } while (DBMethods.CheckHash(hash)); } else { hash = obj.AdvancedSettings.Name; } if (obj.AdvancedSettings?.StartDate != null) { start = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); start = start.AddMilliseconds(obj.AdvancedSettings.StartDate.Value).ToLocalTime(); } if (obj.AdvancedSettings?.ExpireDate != null) { end = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); end = end.AddMilliseconds(obj.AdvancedSettings.ExpireDate.Value).ToLocalTime(); } else { end = end.AddYears(5000); } DBMethods.CreateUrl(hash, obj.Url, start, end); if (obj.AdvancedSettings != null && obj.AdvancedSettings.OnlyHash) { return(Json(new { url = hash })); } return(Json(new { url = _domain + hash })); } return(Json(new { err = "Url не валиден" })); } return(Json(new { err = "Не указан url" })); }
public void Create_absolute_url_should_behave_as_expected() { var request = new RequestUrl("http://server/authorize"); var parameters = new Parameters { { "foo", "foo" }, { "bar", "bar" } }; var url = request.Create(parameters); url.Should().Be("http://server/authorize?foo=foo&bar=bar"); }
public void Multiple_parameter_names_should_behave_as_expected() { var request = new RequestUrl("http://server/authorize"); var parameters = new Parameters { { "foo", "foo" }, { "foo", "bar" } }; var url = request.Create(parameters); url.Should().Be("http://server/authorize?foo=foo&foo=bar"); }
public void Null_values_should_be_skipped() { var request = new RequestUrl("/authorize"); var parameters = new Dictionary <string, string> { { "foo", "foo" }, { "bar", null } }; var url = request.Create(parameters); url.Should().Be("/authorize?foo=foo"); }
public void Special_characters_in_query_param_should_be_encoded_correctly() { var request = new RequestUrl("http://server/authorize"); var parmeters = new { scope = "a b c", clientId = "a+b+c" }; var url = request.Create(parmeters); url.Should().Be("http://server/authorize?scope=a%20b%20c&clientId=a%2Bb%2Bc"); }
internal string GenerateAuthorizationCodeUrl() { var authorizeEndpointUrl = new RequestUrl(this.ApplicationConfiguration.AuthorizeEndpoint); var url = authorizeEndpointUrl.CreateAuthorizeUrl( clientId: this.ApplicationConfiguration.ClientId, scope: this.ApplicationConfiguration.Scope, responseType: OidcConstants.ResponseTypes.Code, responseMode: OidcConstants.ResponseModes.Fragment, redirectUri: this.ApplicationConfiguration.RedirectUri, state: CryptoRandom.CreateUniqueId(), nonce: CryptoRandom.CreateUniqueId()); return(url); }
/// <summary> /// Creates a end_session URL. /// </summary> /// <param name="request">The request.</param> /// <param name="idTokenHint">The id_token hint.</param> /// <param name="postLogoutRedirectUri">The post logout redirect URI.</param> /// <param name="state">The state.</param> /// <param name="extra">The extra parameters.</param> /// <returns></returns> public static string CreateEndSessionUrl(this RequestUrl request, string idTokenHint = null, string postLogoutRedirectUri = null, string state = null, Parameters extra = null) { var values = new Parameters(); values.AddOptional(OidcConstants.EndSessionRequest.IdTokenHint, idTokenHint); values.AddOptional(OidcConstants.EndSessionRequest.PostLogoutRedirectUri, postLogoutRedirectUri); values.AddOptional(OidcConstants.EndSessionRequest.State, state); return(request.Create(values.Merge(extra))); }
public void Create_relative_url_should_behave_as_expected() { var request = new RequestUrl("/authorize"); var parmeters = new { foo = "foo", bar = "bar" }; var url = request.Create(parmeters); url.Should().Be("/authorize?foo=foo&bar=bar"); }
/// <summary> /// Created a Login URL incase you want to Call a different Browser from SignIn() /// </summary> public string GetSigninURL(OAuthSettings oAuthApplication) { var request = new RequestUrl(authorizationUrl); var url = request.CreateAuthorizeUrl( clientId: oAuthApplication.ClientID, responseType: OidcConstants.ResponseTypes.Code, scope: _scope, state: oAuthApplication.ApplicationID.ToString(), redirectUri: oAuthApplication.ReturnUrl); //Wish I could send this in! //UserName = oAuthApplication.UserID, //Password = oAuthApplication.Password, return(url); }
public ResponseInfo <ResponseUrl> GetSODetails([FromBody] RequestUrl data) { ResponseInfo <ResponseUrl> res = new ResponseInfo <ResponseUrl>(); try { res = process.GenerateSoUrl(data); } catch (Exception ex) { throw ex; } return(res); }
public void ProcessRequest_FileSystemThrowsException_ReturnsFolderJson() { var setup = new TestSetup(); var requestUrl = new RequestUrl("FileApi", "files.json", new RequestParameter[] { new RequestParameter("Directory", @"C:\temp") }); setup.FileSystem .Setup(x => x.GetFiles(It.IsAny <string>())) .Throws(new System.IO.IOException("Could not load folder")); var testee = setup.CreateTestee(); var result = Encoding.UTF8.GetString( testee.ProcessRequest(RequestUrl.FromString(requestUrl.ToString()))); Assert.AreEqual("{\"files\":null,\"errorMessage\":\"Could not load folder\"}", result); }
private async Task <IActionResult> StartAuthentication() { // read discovery document to find authorize endpoint var disco = await DiscoveryClient.GetAsync(Constants.Authority); var authorizeUrl = new RequestUrl(disco.AuthorizeEndpoint).CreateAuthorizeUrl( clientId: "mvc.manual", responseType: "id_token", scope: "openid profile", redirectUri: "http://localhost:44078/home/callback", state: "random_state", nonce: "random_nonce", responseMode: "form_post"); return(Redirect(authorizeUrl)); }
/// <summary> /// Sends a Post-Request to the specified url and calls the optional callback after completion. /// </summary> /// <param name="callBack">An optional callback called after completion with the parameter being a boolean that indicates whether or not the request succeeded</param> /// <param name="url">The url to send the request to</param> /// <param name="requestObject">An optional object that is serialized and sent as a json body with the request</param> /// <returns></returns> public void SendPostRequest(RequestUrl url, Action <bool> callBack = null, object requestObject = null) { string requestUrl = RestUrl[url]; if (requestObject != null) { string json = JsonConvert.SerializeObject(requestObject); //Send request with json body StartCoroutine(Post(requestUrl, json, callBack)); } else { //Send request without json body StartCoroutine(Post(requestUrl, "", callBack)); } }
public string CreateAuthorizationRequestUri() { var requestUrl = new RequestUrl(GlobalSettings.Instance.AuthorizeEndpoint); var dic = new Dictionary <string, string>(); dic.Add("client_id", GlobalSettings.Instance.ClientId); dic.Add("client_secret", GlobalSettings.Instance.ClientSecret); dic.Add("response_type", OidcConstants.ResponseTypes.CodeIdToken); dic.Add("scope", "openid profile webapi"); dic.Add("nonce", Guid.NewGuid().ToString("N")); dic.Add("redirect_uri", GlobalSettings.Instance.Callback); dic.Add("code_challenge", CreateCodeChallenge()); dic.Add("code_challenge_method", OidcConstants.CodeChallengeMethods.Sha256); return(requestUrl.Create(dic)); }
public void ProcessRequest_FileSystemReturnsFiles_ReturnsFolderJson() { var setup = new TestSetup(); var requestUrl = new RequestUrl("FileApi", "files.json", new RequestParameter[] { new RequestParameter("Directory", @"C:\temp") }); setup.FileSystem .Setup(x => x.GetFiles(It.Is <string>(y => y == @"C:\temp"))) .Returns(new[] { new File { Kind = FileKind.File, Path = "TestFile" } }); var testee = setup.CreateTestee(); var result = Encoding.UTF8.GetString( testee.ProcessRequest(RequestUrl.FromString(requestUrl.ToString()))); Assert.AreEqual("{\"files\":[{\"kind\":0,\"path\":\"TestFile\"}],\"errorMessage\":null}", result); }
public override int GetHashCode() { int hash = 1; if (RequestMethod.Length != 0) { hash ^= RequestMethod.GetHashCode(); } if (RequestUrl.Length != 0) { hash ^= RequestUrl.GetHashCode(); } if (RequestSize != 0L) { hash ^= RequestSize.GetHashCode(); } if (Status != 0) { hash ^= Status.GetHashCode(); } if (ResponseSize != 0L) { hash ^= ResponseSize.GetHashCode(); } if (UserAgent.Length != 0) { hash ^= UserAgent.GetHashCode(); } if (RemoteIp.Length != 0) { hash ^= RemoteIp.GetHashCode(); } if (Referer.Length != 0) { hash ^= Referer.GetHashCode(); } if (CacheHit != false) { hash ^= CacheHit.GetHashCode(); } if (ValidatedWithOriginServer != false) { hash ^= ValidatedWithOriginServer.GetHashCode(); } return(hash); }