Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #666 from squid808/CustomAuthParams
Custom Auth Query Params
- Loading branch information
Showing
8 changed files
with
233 additions
and
7 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
85 changes: 85 additions & 0 deletions
85
Src/Support/GoogleApis.Auth.Tests/OAuth2/Flows/GoogleAuthorizationCodeFlowTests.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,85 @@ | ||
/* | ||
Copyright 2016 Google Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
using Moq; | ||
using NUnit.Framework; | ||
|
||
using Google.Apis.Auth.OAuth2.Flows; | ||
using Google.Apis.Auth.OAuth2.Requests; | ||
using Google.Apis.Auth.OAuth2.Responses; | ||
using Google.Apis.Http; | ||
using Google.Apis.Util.Store; | ||
|
||
namespace Google.Apis.Auth.OAuth2.Flows | ||
{ | ||
/// <summary>Tests for <see cref="Google.Apis.Auth.OAuth2.Flows.GoogleAuthorizationCodeFlow"/>.</summary> | ||
public class GoogleAuthorizationCodeFlowTests | ||
{ | ||
GoogleAuthorizationCodeFlow.Initializer initializer { get; set; } | ||
List<KeyValuePair<string, string>> userDefinedParams { get; set; } | ||
|
||
[SetUp] | ||
public void GoogleAuthorizationCodeFlowTestSetup() | ||
{ | ||
string revokeTokenUrl = "Revoke Token Url"; | ||
bool? includeGrantedScopes = true; | ||
userDefinedParams = new List<KeyValuePair<string, string>> | ||
{ | ||
new KeyValuePair<string,string>("customParam1","customVal1"), | ||
new KeyValuePair<string,string>("customParam2","customVal2") | ||
}; | ||
|
||
initializer = new GoogleAuthorizationCodeFlow.Initializer() | ||
{ | ||
RevokeTokenUrl = revokeTokenUrl, | ||
IncludeGrantedScopes = includeGrantedScopes, | ||
UserDefinedQueryParams = userDefinedParams, | ||
ClientSecrets = new ClientSecrets() | ||
}; | ||
} | ||
|
||
[Test] | ||
public void ConstructorTest() | ||
{ | ||
var flow = new GoogleAuthorizationCodeFlow(initializer); | ||
|
||
Assert.That(flow.RevokeTokenUrl, Is.EqualTo(initializer.RevokeTokenUrl)); | ||
Assert.That(flow.IncludeGrantedScopes, Is.EqualTo(initializer.IncludeGrantedScopes)); | ||
Assert.That(flow.UserDefinedQueryParams, Is.EqualTo(initializer.UserDefinedQueryParams)); | ||
} | ||
|
||
[Test] | ||
public void CreateAuthorizationCodeRequestTest() | ||
{ | ||
var flow = new GoogleAuthorizationCodeFlow(initializer); | ||
|
||
var request = flow.CreateAuthorizationCodeRequest("TestRedirectUri") as GoogleAuthorizationCodeRequestUrl; | ||
|
||
Assert.AreEqual(request.AccessType, "offline"); | ||
Assert.AreEqual(request.IncludeGrantedScopes, "true"); | ||
Assert.AreEqual(request.UserDefinedQueryParams, userDefinedParams); | ||
Assert.AreEqual(request.RedirectUri, "TestRedirectUri"); | ||
} | ||
|
||
//TODO(squid808): Add tests for RevokeToken. | ||
} | ||
} |
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
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
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
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
83 changes: 83 additions & 0 deletions
83
Src/Support/GoogleApis.Tests/Apis/Requests/Parameters/ParameterUtilsTest.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,83 @@ | ||
/* | ||
Copyright 2016 Google Inc | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
using System.Collections.Generic; | ||
|
||
using NUnit.Framework; | ||
|
||
using Google.Apis.Util; | ||
using Google.Apis.Requests; | ||
using Google.Apis.Requests.Parameters; | ||
|
||
namespace Google.Apis.Tests.Apis.Requests | ||
{ | ||
/// <summary>Tests for <see cref="Google.Apis.Requests.Parameters.ParameterUtils"/>.</summary> | ||
[TestFixture] | ||
public class ParameterUtilsTest | ||
{ | ||
private class TestRequestUrl | ||
{ | ||
[Google.Apis.Util.RequestParameterAttribute("first_query_param", | ||
Google.Apis.Util.RequestParameterType.Query)] | ||
public string FirstParam { get; set; } | ||
|
||
[Google.Apis.Util.RequestParameterAttribute("second_query_param", | ||
Google.Apis.Util.RequestParameterType.Query)] | ||
public string SecondParam { get; set; } | ||
|
||
[Google.Apis.Util.RequestParameterAttribute("query_param_attribute_name", | ||
Google.Apis.Util.RequestParameterType.UserDefinedQueries)] | ||
public List<KeyValuePair<string, string>> ParamsCollection { get; set; } | ||
|
||
public System.Uri Build() | ||
{ | ||
var builder = new RequestBuilder() | ||
{ | ||
BaseUri = new System.Uri("//revokeTokenUrl") | ||
}; | ||
ParameterUtils.InitParameters(builder, this); | ||
return builder.BuildUri(); | ||
} | ||
} | ||
|
||
[Test] | ||
public void IterateParametersTest() | ||
{ | ||
var request = new TestRequestUrl() | ||
{ | ||
FirstParam = "firstOne", | ||
SecondParam = "secondOne", | ||
ParamsCollection = new List<KeyValuePair<string, string>>{ | ||
new KeyValuePair<string,string>("customParam1","customVal1"), | ||
new KeyValuePair<string,string>("customParam2","customVal2") | ||
} | ||
}; | ||
|
||
var result = request.Build().AbsoluteUri; | ||
|
||
//Parametera were given a name and a value, so both appear in the URI. | ||
Assert.That(result, Contains.Substring("first_query_param=firstOne")); | ||
Assert.That(result, Contains.Substring("second_query_param=secondOne")); | ||
|
||
//Custom parameters are key value pairs representing parameter names and values respectively. | ||
Assert.That(result, Contains.Substring("customParam1=customVal1")); | ||
Assert.That(result, Contains.Substring("customParam2=customVal2")); | ||
|
||
//The parameter name for the custom parameters does not carry through to the resulting URI. | ||
Assert.IsFalse(result.Contains("query_param_attribute_name")); | ||
} | ||
} | ||
} |
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