Skip to content

Commit

Permalink
Changes related to lib to be merged later
Browse files Browse the repository at this point in the history
  • Loading branch information
nimisha84 committed Jun 27, 2017
1 parent f142020 commit c1ce13d
Show file tree
Hide file tree
Showing 109 changed files with 7,706 additions and 9 deletions.
18 changes: 17 additions & 1 deletion IPPDotNetDevKitCSV3/Code/.vs/config/applicationhost.config
Original file line number Diff line number Diff line change
Expand Up @@ -162,12 +162,28 @@
</site>
<site name="IDGOauthSample" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\QuickBooks-V3-DotNET-SDK.git\IPPDotNetDevKitCSV3\Sample app for testing SDK\IDG Oauth Sample\IDGOauthSample" />
<virtualDirectory path="/" physicalPath="F:\QuickBooks-V3-DotNET-SDK.git\IPPDotNetDevKitCSV3\Sample app for testing SDK\OAuth1\IDG Oauth Sample\IDGOauthSample" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:65281:localhost" />
</bindings>
</site>
<site name="SampleAppOAuth2_UsingSDK" id="3">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\QuickBooks-V3-DotNET-SDK.git\IPPDotNetDevKitCSV3\Sample app for testing SDK\OAuth2\SampleAppOAuth2Lib" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:52626:localhost" />
</bindings>
</site>
<site name="OAuth2_SampleApp_Dotnet_UsingSDK" id="4">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="F:\OAuth2-Dotnet_UsingSDK\OAuth2_SampleApp_Dotnet\OAuth2_SampleApp_Dotnet" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:59135:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
Expand Down
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>
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);

}
}
}
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");
//}
}
}
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");



}
}
}
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"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"kid": "r4p5SbL2qaFehFzhj8gI",
"alg": "RS256"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"error": "error",
"error_description": "error_description"

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"error": "error"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"token_type": "bearer",
"expires_in": 3600,
"refresh_token": "L311478109728uVoOkDSUCl4s8FDRvjHR6kUKz0RHe3WtZQuB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JpYXQiOjE0NjI1NTc3Mjh9.BIJ9x_WPEOZsLJfQE3mGji_Q15j_rdlTyFYELiJM-W92fWSLC-TLEwCp5IrRhDWMvyvrLSMZCEdQALYQpbVy8uKI22JgGWYvkwNEDweOjbYzyt33F4xtn3GGcW9nAwRtA3M19qquWyi7G0kcCZUDN8RfUXz2qKMJ6KPOfLVe2UQ"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"statuscode": "200"
}
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"

}
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"
}
}
Loading

0 comments on commit c1ce13d

Please sign in to comment.