-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changes related to lib to be merged later
- Loading branch information
Showing
109 changed files
with
7,706 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/App.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<appSettings> | ||
<add key="DiscoveryAuthority" value="https://oauth.platform.intuit.com/op/v1"/> | ||
<add key="DiscoveryUrlProduction" value="https://developer.api.intuit.com/.well-known/openid_configuration"/> | ||
<add key="DiscoveryUrlSandbox" value="https://developer.api.intuit.com/.well-known/openid_sandbox_configuration/"/> | ||
</appSettings> | ||
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup></configuration> |
47 changes: 47 additions & 0 deletions
47
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/AuthorizeRequestTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright (c) Intuit All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Intuit.OAuth2PlatformClient; | ||
|
||
|
||
namespace Intuit.OAuth2PlatformClient.UnitTests | ||
{ | ||
[TestClass] | ||
public class AuthorizeRequestTests | ||
{ | ||
[TestMethod] | ||
public void Create_absolute_url_should_behave_as_expected() | ||
{ | ||
var request = new AuthorizeRequest("http://server/authorize"); | ||
|
||
var parmeters = new | ||
{ | ||
foo = "foo", | ||
bar = "bar" | ||
}; | ||
|
||
var url = request.Create(parmeters); | ||
Assert.AreEqual("http://server/authorize?foo=foo&bar=bar", url); | ||
|
||
} | ||
|
||
[TestMethod] | ||
public void Create_relative_url_should_behave_as_expected() | ||
{ | ||
var request = new AuthorizeRequest(new Uri("/authorize", UriKind.Relative)); | ||
|
||
var parmeters = new | ||
{ | ||
foo = "foo", | ||
bar = "bar" | ||
}; | ||
|
||
var url = request.Create(parmeters); | ||
Assert.AreEqual("/authorize?foo=foo&bar=bar", url); | ||
|
||
} | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/AuthorizeResponseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
// Copyright (c) Intuit All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using Intuit.OAuth2PlatformClient; | ||
|
||
|
||
namespace Intuit.OAuth2PlatformClient.UnitTests | ||
{ | ||
[TestClass] | ||
public class AuthorizeResponseTests | ||
{ | ||
[TestMethod] | ||
public void Error_Response_with_QueryString() | ||
{ | ||
var url = "https://server/callback?error=foo"; | ||
|
||
var response = new AuthorizeResponse(url); | ||
Assert.AreEqual(true,response.IsError); | ||
Assert.AreEqual("foo", response.Error); | ||
} | ||
|
||
[TestMethod] | ||
public void Error_Response_with_HashFragment() | ||
{ | ||
var url = "https://server/callback#error=foo"; | ||
|
||
var response = new AuthorizeResponse(url); | ||
|
||
Assert.AreEqual(true, response.IsError); | ||
Assert.AreEqual("foo", response.Error); | ||
} | ||
|
||
[TestMethod] | ||
public void Error_Response_with_QueryString_and_HashFragment() | ||
{ | ||
var url = "https://server/callback?error=foo#_=_"; | ||
|
||
var response = new AuthorizeResponse(url); | ||
|
||
Assert.AreEqual(true, response.IsError); | ||
Assert.AreEqual("foo", response.Error); | ||
} | ||
|
||
[TestMethod] | ||
public void Code_Response_with_QueryString() | ||
{ | ||
var url = "https://server/callback?state=security_token=138r5719ru3e1&url=https://server/callback&code=foo"; | ||
|
||
var response = new AuthorizeResponse(url); | ||
|
||
|
||
Assert.AreEqual(false, response.IsError); | ||
Assert.AreEqual("foo", response.Code); | ||
|
||
Assert.AreEqual("security_token=138r5719ru3e1", response.Values["state"].ToString()); | ||
Assert.AreEqual("security_token=138r5719ru3e1", response.TryGet("state").ToString()); | ||
|
||
} | ||
|
||
|
||
//[TestMethod] | ||
//public void form_post_format_should_parse() | ||
//{ | ||
// var form = "id_token=foo&code=bar&scope=baz&session_state=quux"; | ||
// var response = new AuthorizeResponse(form); | ||
|
||
// response.IsError.Should().BeFalse(); | ||
// response.IdentityToken.Should().Be("foo"); | ||
// response.Code.Should().Be("bar"); | ||
// response.Scope.Should().Be("baz"); | ||
// response.Values["session_state"].Should().Be("quux"); | ||
//} | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/DiscoveryClientTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// Copyright (c) Intuit All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information. | ||
|
||
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting; | ||
using System; | ||
using System.IO; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Intuit.OAuth2PlatformClient; | ||
using System.Configuration; | ||
|
||
|
||
namespace Intuit.OAuth2PlatformClient.UnitTests | ||
{ | ||
[TestClass] | ||
public class DiscoveryClientTests | ||
{ | ||
NetworkHandler _successHandler; | ||
string _endpoint = ConfigurationManager.AppSettings["DiscoveryUrlProduction"]; | ||
|
||
public DiscoveryClientTests() | ||
{ | ||
var discoFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documents", "discovery.json");//Nimisha | ||
var document = File.ReadAllText(discoFileName); | ||
|
||
var jwksFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Documents", "discovery.json");//Nimisha | ||
var jwks = File.ReadAllText(jwksFileName); | ||
|
||
_successHandler = new NetworkHandler(request => | ||
{ | ||
if (request.RequestUri.AbsoluteUri.EndsWith("jwks")) | ||
{ | ||
return jwks; | ||
} | ||
return document; | ||
}, HttpStatusCode.OK); | ||
} | ||
|
||
[TestMethod] | ||
[ExpectedException(typeof(InvalidOperationException))] | ||
public void malformed_authority_url_should_throw() | ||
{ | ||
string input = "https:something_weird_https://something_other"; | ||
var client = new DiscoveryClient(input); | ||
|
||
//Assert.AreEqual(e.Message,("Malformed authority URL")); | ||
Assert.Fail(); | ||
|
||
|
||
|
||
} | ||
|
||
[TestMethod] | ||
public void various_urls_should_normalize() | ||
{ | ||
string input = "https://server:123/"; | ||
var client = new DiscoveryClient(input); | ||
|
||
Assert.AreEqual(client.Url,"https://server:123/.well-known/openid_configuration"); | ||
Assert.AreEqual(client.Authority,"https://server:123"); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Http_error_should_be_handled_correctly() | ||
{ | ||
var handler = new NetworkHandler(HttpStatusCode.NotFound, "not found"); | ||
|
||
var client = new DiscoveryClient(_endpoint, handler); | ||
var disco = await client.GetAsync(); | ||
|
||
Assert.AreEqual(disco.IsError, true); | ||
Assert.AreEqual(disco.ErrorType,(ResponseErrorType.Http)); | ||
Assert.AreEqual(disco.Error.StartsWith("Error connecting to"), true); | ||
Assert.AreEqual(disco.Error.EndsWith("not found"), true); | ||
Assert.AreEqual(disco.StatusCode,(HttpStatusCode.NotFound)); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Exception_should_be_handled_correctly() | ||
{ | ||
var handler = new NetworkHandler(new Exception("error")); | ||
|
||
var client = new DiscoveryClient(_endpoint, handler); | ||
var disco = await client.GetAsync(); | ||
|
||
Assert.AreEqual(disco.IsError, true); | ||
Assert.AreEqual(disco.ErrorType, (ResponseErrorType.Exception)); | ||
Assert.AreEqual(disco.Error.StartsWith("Error connecting to"), true); | ||
Assert.AreEqual(disco.Error.EndsWith("error"), true); | ||
} | ||
|
||
[TestMethod] | ||
public async Task TryGetValue_calls_should_behave_as_excected() | ||
{ | ||
var client = new DiscoveryClient(_endpoint, _successHandler); | ||
var disco = await client.GetAsync(); | ||
|
||
|
||
Assert.AreEqual(disco.IsError, false); | ||
Assert.IsNotNull(disco.TryGetValue(OidcConstants.Discovery.AuthorizationEndpoint)); | ||
Assert.AreEqual(disco.TryGetString(OidcConstants.Discovery.AuthorizationEndpoint), "https://appcenter.intuit.com/connect/oauth2"); | ||
Assert.IsNull(disco.TryGetValue("unknown")); | ||
Assert.IsNull(disco.TryGetString("unknown")); | ||
} | ||
|
||
[TestMethod] | ||
public async Task Strongly_typed_accessors_should_behave_as_expected() | ||
{ | ||
var client = new DiscoveryClient(_endpoint, _successHandler); | ||
var disco = await client.GetAsync(); | ||
|
||
Assert.AreEqual(disco.IsError, false); | ||
|
||
Assert.AreEqual(disco.TokenEndpoint, "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer"); | ||
Assert.AreEqual(disco.AuthorizeEndpoint, "https://appcenter.intuit.com/connect/oauth2"); | ||
Assert.AreEqual(disco.UserInfoEndpoint, "https://accounts.intuit.com/v1/openid_connect/userinfo"); | ||
Assert.AreEqual(disco.RevocationEndpoint, "https://developer.api.intuit.com/v2/oauth2/tokens/revoke"); | ||
Assert.AreEqual(disco.JwksUri, "https://oauth.platform.intuit.com/op/v1/jwks"); | ||
|
||
|
||
|
||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/discovery.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
{ | ||
"issuer": "https://oauth.platform.intuit.com/op/v1", | ||
"authorization_endpoint": "https://appcenter.intuit.com/connect/oauth2", | ||
"token_endpoint": "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer", | ||
"userinfo_endpoint": "https://accounts.intuit.com/v1/openid_connect/userinfo", | ||
"revocation_endpoint": "https://developer.api.intuit.com/v2/oauth2/tokens/revoke", | ||
"jwks_uri": "https://oauth.platform.intuit.com/op/v1/jwks", | ||
"response_types_supported": [ | ||
"code" | ||
], | ||
"subject_types_supported": [ | ||
"public" | ||
], | ||
"id_token_signing_alg_values_supported": [ | ||
"RS256" | ||
], | ||
"scopes_supported": [ | ||
"openid", | ||
"email", | ||
"profile", | ||
"address", | ||
"phone" | ||
], | ||
"token_endpoint_auth_methods_supported": [ | ||
"client_secret_post", | ||
"client_secret_basic" | ||
], | ||
"claims_supported": [ | ||
"aud", | ||
"exp", | ||
"iat", | ||
"iss", | ||
"realmid", | ||
"sub" | ||
] | ||
} |
4 changes: 4 additions & 0 deletions
4
IPPDotNetDevKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/discovery_jwks.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"kid": "r4p5SbL2qaFehFzhj8gI", | ||
"alg": "RS256" | ||
} |
5 changes: 5 additions & 0 deletions
5
...evKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/failure_token_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"error": "error", | ||
"error_description": "error_description" | ||
|
||
} |
3 changes: 3 additions & 0 deletions
3
...ode/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/failure_token_revocation_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"error": "error" | ||
} |
8 changes: 8 additions & 0 deletions
8
...V3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/success_refreshtoken_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"token_type": "bearer", | ||
"expires_in": 3600, | ||
"refresh_token": "L311478109728uVoOkDSUCl4s8FDRvjHR6kUKz0RHe3WtZQuBq", | ||
"x_refresh_token_expires_in": 15552000, | ||
"access_token": "eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..KM1_Fezsm6BUSaqqfTedaA.dBUCZWiVmjH8CdpXeh_pmaM3kJlJkLEqJlfmavwGQDThcf94fbj9nBZkjEPLvBcQznJnEmltCIvsTGX0ue_w45h7_yn1zBoOb-1QIYVE0E5TI9z4tMUgQNeUkD1w-X8ECVraeOEecKaqSW32Oae0yfKhDFbwQZnptbPzIDaqiduiM_qEFcbAzT-7-znVd09lE3BTpdMF9MYqWdI5wPqbP8okMI0l8aa-UVFDH9wtli80zhHb7GgI1eudqRQc0sS9zWWbI-eRcIhjcIndNUowSFCrVcYG6_kIj3uRUmIV-KjJUeXdSV9kcTAWL9UGYoMnTPQemStBd2thevPUuvKrPdz3EDft-RVRLQYUJSJ1oA2Q213Uv4kFQJgNinYuG9co_qAE6A2YzVn6A8jCap6qGR6vWHFoLjM2TutVd6eOeYoL2bb7jlQALEpYGj4E1h3y2xZITWvnmI0CEL_dYQX6B3QTO36TDaVl9WnTaCCgAcP6bt70rFlPYbCjOxLoI6qFm5pUwGLLp67JZ36grc58k7NIyKJ8dLJUL_Q9r1WoUvw.ZS298t_u7dSlkfajxLfO9Q", | ||
"id_token": "eyJraWQiOiJyNHA1U2JMMnFhRmVoRnpoajhnSSIsImFsZyI6IlJTMjU2In0.eyJzdWIiOiJiMDUzZDk5NC0wN2Q1LTQ2OGQtYjdlZS0yMmUzNDlkMmU3MzkiLCJhdWQiOlsiTDM5ZWxTdWJGeGpQT1NwZFpvWVdSS2lDQ0U2VElOanY2N1JvYUU4ekJxYkl4eGI0bEsiXSwicmVhbG1pZCI6IjExMDgwMzM0NzEiLCJhdXRoX3RpbWUiOjE0NjI1NTQ0NzUsImlzcyI6Imh0dHBzOlwvXC9vYXV0aC1lMmUucGxhdGZvcm0uaW50dWl0LmNvbVwvb2F1dGgyXC92MVwvb3BcL3YxIiwiZXhwIjoxNDYyNTYxMzI4LCJpYXQiOjE0NjI1NTc3Mjh9.BIJ9x_WPEOZsLJfQE3mGji_Q15j_rdlTyFYELiJM-W92fWSLC-TLEwCp5IrRhDWMvyvrLSMZCEdQALYQpbVy8uKI22JgGWYvkwNEDweOjbYzyt33F4xtn3GGcW9nAwRtA3M19qquWyi7G0kcCZUDN8RfUXz2qKMJ6KPOfLVe2UQ" | ||
} |
3 changes: 3 additions & 0 deletions
3
...SV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/success_revoketoken_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"statuscode": "200" | ||
} |
9 changes: 9 additions & 0 deletions
9
...evKitCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/success_token_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"token_type": "bearer", | ||
"expires_in": 3600, | ||
"refresh_token": "refresh_token", | ||
"x_refresh_token_expires_in": 15552000, | ||
"access_token": "access_token", | ||
"id_token": "id_token" | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...itCSV3/Code/Intuit.Ipp.OAuth2PlatformClient.Test/Documents/success_userinfo_response.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"sub": "1182d6ec-2a1f-4aa3-af3f-bb3b95db45af", | ||
"email": "john@doe.com", | ||
"emailVerified": true, | ||
"givenName": "John", | ||
"familyName": "Doe", | ||
"phoneNumber": "+1 6305555555", | ||
"phoneNumberVerified": false, | ||
"address": { | ||
"streetAddress": "2007 saint julien ct", | ||
"locality": "mountain view", | ||
"region": "CA", | ||
"postalCode": "94043", | ||
"country": "US" | ||
} | ||
} |
Oops, something went wrong.