-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Feature)|Add customParameters to OAuth2AuthorizationResponse (#104)
### Summary This change will allow consuming applications of third party APIs to react accordingly when the user does not approve all requested scope permissions. ### Implementation - Added `scope` property to the `OAuth2AuthorizationResponse` object as an array of Strings. - Hooked this property up in the `OAuth2AuthorizationRedirectHandler`. The query string parameter `scope` is converted into a String array split by commas. This value is optional as users may choose to accept all requested permissions or none. ### Test Plan - Added test to `OAuth2AuthorizationCodeTokenGrantStrategyTests` to verify the scope is not altered. - Tested in live OAuth2SafariAuthorizationStrategy using Strava API, accepting and denying requested scope permissions.
- Loading branch information
1 parent
c25fa79
commit 86141e8
Showing
6 changed files
with
99 additions
and
2 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
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
45 changes: 45 additions & 0 deletions
45
Tests/ConduitTests/Auth/OAuth2AuthorizationStrategyTests.swift
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,45 @@ | ||
// | ||
// OAuth2AuthorizationStrategyTests.swift | ||
// Conduit | ||
// | ||
// Created by Anthony Lipscomb on 8/28/18. | ||
// Copyright © 2018 MINDBODY. All rights reserved. | ||
// | ||
|
||
import XCTest | ||
@testable import Conduit | ||
|
||
class OAuth2AuthorizationStrategyTests: XCTestCase { | ||
|
||
let redirectURI = "x-oauth2-myapp://authorize" | ||
let customParameters: [String: String] = ["some_id": "123abc"] | ||
let clientIdentifier: String = "Conduit" | ||
let scope = "private_read,write" | ||
|
||
private func makeStrategy() throws -> MockSafariAuthorizationStrategy { | ||
return MockSafariAuthorizationStrategy() | ||
} | ||
|
||
func testAuthorize() throws { | ||
var request = OAuth2AuthorizationRequest(clientIdentifier: clientIdentifier) | ||
request.redirectURI = try URL(absoluteString: redirectURI) | ||
request.scope = scope | ||
request.state = AuthTestUtilities.makeSecureRandom(length: 32) | ||
request.clientSecret = "shhh, it's a secret" | ||
request.additionalParameters = customParameters | ||
|
||
let expect = expectation(description: "Expect the query parameters to be returned in the header of the resposne") | ||
|
||
var response: OAuth2AuthorizationResponse! | ||
try makeStrategy().authorize(request: request) { authorizeResponse in | ||
XCTAssertNil(authorizeResponse.error) | ||
response = authorizeResponse.value | ||
expect.fulfill() | ||
} | ||
|
||
wait(for: [expect], timeout: TimeInterval(5)) | ||
XCTAssertNotNil(response.code) | ||
XCTAssert(response.customParameters.contains { $0 == "scope" && $1 == scope } == true) | ||
XCTAssertEqual(response.state, request.state) | ||
} | ||
} |