public void BuildUri_AllPartsAreRestored() { var parameters = new Dictionary<string, string>() { { "wheels", "4"}, {"year", "2001"} // overrides query string parameter }; var inputUri = new Uri("https://www.example.com:88/equipment/cars?year=1992&color=blue"); var uriParts = new UrlParts(inputUri, parameters); Uri resultUri = uriParts.BuildUri(); Assert.AreEqual(inputUri.Scheme, resultUri.Scheme); Assert.AreEqual(inputUri.Host, resultUri.Host); Assert.AreEqual(inputUri.Port, resultUri.Port); Assert.AreEqual(inputUri.AbsolutePath, resultUri.AbsolutePath); NameValueCollection queryParameters = HttpUtility.ParseQueryString(resultUri.Query); Assert.AreEqual("4", queryParameters["wheels"]); Assert.AreEqual("2001", queryParameters["year"]); Assert.AreEqual("blue", queryParameters["color"]); }
public Uri GetAuthorizationUri() { Dictionary<string, string> parameters = GetAuthorizationRequestParameters(); var urlParts = new UrlParts(AuthorizationEndpoint, parameters); Uri uri = urlParts.BuildUri(); return uri; }
protected virtual ProtocolRequest CreateProtocolRequest(UrlParts requestUrl, Dictionary<string,string> parameters) { var oauthRequest = new ProtocolRequest() { Url = requestUrl, BodyParameters = parameters }; return oauthRequest; }
public void Ctor_WhenUriIsProvided_AllPartsAreKept() { var testUri = new Uri("https://www.example.com:88/equipment/cars?year=1992&color=blue"); var uriParts = new UrlParts(testUri); Assert.AreEqual("https://www.example.com:88", uriParts.ProtocolAndHost); Assert.AreEqual("1992", uriParts.QueryParameters["year"]); Assert.AreEqual("blue", uriParts.QueryParameters["color"]); Assert.AreEqual("/equipment/cars", uriParts.Path); }
public void Ctor_WhenUriAndDictionaryIsProvided_DictionaryParametersOverride() { var parameters = new Dictionary<string,string>() { { "wheels", "4"}, {"year", "2001"} // overrides query string parameter }; var testUri = new Uri("https://www.example.com:88/equipment/cars?year=1992&color=blue"); var uriParts = new UrlParts(testUri, parameters); Assert.AreEqual("2001", uriParts.QueryParameters["year"]); Assert.AreEqual("blue", uriParts.QueryParameters["color"]); Assert.AreEqual("4", uriParts.QueryParameters["wheels"]); }
public SecurityToken RequestAccessToken() { Dictionary<string,string> bodyParameters = CreateAccessTokenRequestParameters(); UrlParts url = new UrlParts(TokenEndpoint) { Path = TokenEndpoint.AbsolutePath }; ProtocolRequest oauthRequest = CreateProtocolRequest(url, bodyParameters); ProtocolResponse oauthResponse = _httpClient.SendRequest(oauthRequest); SecurityToken token = CreateSecurityToken(oauthResponse); return token; }
public void SetAccessCodeRepsonse(Uri resultUrl) { var urlParts = new UrlParts(resultUrl); string state = GetStateValueFromParameters(urlParts.QueryParameters); if (!string.IsNullOrEmpty(state)) { VerifyStateParameter(state); } string code = GetAuthorizationCodeFromParameters(urlParts.QueryParameters); if (string.IsNullOrEmpty(code)) { throw new ArgumentException("No access code found"); } _accessCode = code; }
protected string RequestAccessToken() { if (_cachedToken == null || _cachedToken.Expiration < DateTime.Now.AddMinutes(1)) { Dictionary<string, string> bodyParameters = CreateAccessTokenRequestParameters(); UrlParts url = new UrlParts(TokenEndpoint) { Path = TokenEndpoint.AbsolutePath }; ProtocolRequest oauthRequest = CreateProtocolRequest(url, bodyParameters); ProtocolResponse oauthResponse = _httpClient.SendRequest(oauthRequest); _cachedToken = ExtractSecurityTokenFromResponse(oauthResponse); } return _cachedToken.Token; }