forked from ChimeHQ/OAuthenticator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Google optional authorization parameters. (ChimeHQ#15)
* Update GoogleAPI to support optional authentication parameters Cleanup functions to remove unneeded parameters * Add new tests to ensure AuthorizationURL provider is properly including the optional parameters in the constructed URL. * Specify userAuthenticator for platforms that need it --------- Co-authored-by: Matt <[email protected]>
- Loading branch information
1 parent
7f4c920
commit b33e2e0
Showing
2 changed files
with
94 additions
and
8 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
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 |
---|---|---|
|
@@ -32,4 +32,68 @@ final class GoogleTests: XCTestCase { | |
sleep(5) | ||
XCTAssert(!login.accessToken.valid) | ||
} | ||
|
||
func testSuppliedParameters() throws { | ||
let googleParameters = GoogleAPI.GoogleAPIParameters(includeGrantedScopes: true, loginHint: "[email protected]") | ||
|
||
XCTAssertNotNil(googleParameters.loginHint) | ||
XCTAssertTrue(googleParameters.includeGrantedScopes) | ||
|
||
let callback = URL(string: "callback://google_api") | ||
XCTAssertNotNil(callback) | ||
|
||
let creds = AppCredentials(clientId: "client_id", clientPassword: "client_pwd", scopes: ["scope1", "scope2"], callbackURL: callback!) | ||
let tokenHandling = GoogleAPI.googleAPITokenHandling(with: googleParameters) | ||
let config = Authenticator.Configuration( | ||
appCredentials: creds, | ||
tokenHandling: tokenHandling, | ||
userAuthenticator: Authenticator.failingUserAuthenticator | ||
) | ||
|
||
// Validate URL is properly constructed | ||
let googleURLProvider = try config.tokenHandling.authorizationURLProvider(creds) | ||
|
||
let urlComponent = URLComponents(url: googleURLProvider, resolvingAgainstBaseURL: true) | ||
XCTAssertNotNil(urlComponent) | ||
XCTAssertEqual(urlComponent!.scheme, GoogleAPI.scheme) | ||
|
||
// Validate query items inclusion and value | ||
XCTAssertNotNil(urlComponent!.queryItems) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.name == GoogleAPI.includeGrantedScopeKey })) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.name == GoogleAPI.loginHint })) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.value == String(true) })) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.value == "[email protected]" })) | ||
} | ||
|
||
func testDefaultParameters() throws { | ||
let googleParameters = GoogleAPI.GoogleAPIParameters() | ||
|
||
XCTAssertNil(googleParameters.loginHint) | ||
XCTAssertTrue(googleParameters.includeGrantedScopes) | ||
|
||
let callback = URL(string: "callback://google_api") | ||
XCTAssertNotNil(callback) | ||
|
||
let creds = AppCredentials(clientId: "client_id", clientPassword: "client_pwd", scopes: ["scope1", "scope2"], callbackURL: callback!) | ||
let tokenHandling = GoogleAPI.googleAPITokenHandling(with: googleParameters) | ||
let config = Authenticator.Configuration( | ||
appCredentials: creds, | ||
tokenHandling: tokenHandling, | ||
userAuthenticator: Authenticator.failingUserAuthenticator | ||
) | ||
|
||
// Validate URL is properly constructed | ||
let googleURLProvider = try config.tokenHandling.authorizationURLProvider(creds) | ||
|
||
let urlComponent = URLComponents(url: googleURLProvider, resolvingAgainstBaseURL: true) | ||
XCTAssertNotNil(urlComponent) | ||
XCTAssertEqual(urlComponent!.scheme, GoogleAPI.scheme) | ||
|
||
// Validate query items inclusion and value | ||
XCTAssertNotNil(urlComponent!.queryItems) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.name == GoogleAPI.includeGrantedScopeKey })) | ||
XCTAssertFalse(urlComponent!.queryItems!.contains(where: { $0.name == GoogleAPI.loginHint })) | ||
XCTAssertTrue(urlComponent!.queryItems!.contains(where: { $0.value == String(true) })) | ||
} | ||
|
||
} |