-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEATURE: Request authentication token
- Loading branch information
1 parent
ff9ae08
commit 4182e6d
Showing
82 changed files
with
293 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// | ||
// AuthenticateURLBuilder.swift | ||
// TMDb | ||
// | ||
// Copyright © 2024 Adam Young. | ||
// | ||
// 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. | ||
// | ||
|
||
import Foundation | ||
|
||
final class AuthenticateURLBuilder: AuthenticateURLBuilding { | ||
|
||
private let baseURL: URL | ||
|
||
init(baseURL: URL) { | ||
self.baseURL = baseURL | ||
} | ||
|
||
func authenticateURL(with requestToken: String) -> URL { | ||
authenticateURL(with: requestToken, redirectURL: nil) | ||
} | ||
|
||
func authenticateURL(with requestToken: String, redirectURL: URL?) -> URL { | ||
var url = baseURL | ||
.appendingPathComponent("authenticate") | ||
.appendingPathComponent(requestToken) | ||
|
||
if let redirectURL { | ||
url = url.appendingQueryItem(name: "redirect_to", value: redirectURL.absoluteString) | ||
} | ||
|
||
return url | ||
} | ||
|
||
} |
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
File renamed without changes.
File renamed without changes.
28 changes: 28 additions & 0 deletions
28
Sources/TMDb/Services/Authentication/AuthenticateURLBuilding.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,28 @@ | ||
// | ||
// AuthenticateURLBuilding.swift | ||
// TMDb | ||
// | ||
// Copyright © 2024 Adam Young. | ||
// | ||
// 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. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AuthenticateURLBuilding { | ||
|
||
func authenticateURL(with requestToken: String) -> URL | ||
|
||
func authenticateURL(with requestToken: String, redirectURL: URL?) -> URL | ||
|
||
} |
File renamed without changes.
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// | ||
// AuthenticateURLBuilderTests.swift | ||
// TMDb | ||
// | ||
// Copyright © 2024 Adam Young. | ||
// | ||
// 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. | ||
// | ||
|
||
@testable import TMDb | ||
import XCTest | ||
|
||
final class AuthenticateURLBuilderTests: XCTestCase { | ||
|
||
var builder: AuthenticateURLBuilder! | ||
var baseURL: URL! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
baseURL = URL(string: "https://some.domain.com") | ||
builder = AuthenticateURLBuilder(baseURL: baseURL) | ||
} | ||
|
||
override func tearDown() { | ||
builder = nil | ||
baseURL = nil | ||
super.tearDown() | ||
} | ||
|
||
func testAuthenticateURLReturnsURL() { | ||
let requestToken = "qwertyuiop" | ||
let expectedURL = baseURL | ||
.appendingPathComponent("authenticate") | ||
.appendingPathComponent(requestToken) | ||
|
||
let url = builder.authenticateURL(with: requestToken) | ||
|
||
XCTAssertEqual(url, expectedURL) | ||
} | ||
|
||
func testAuthenticateURLWithRedirectURLReturnsURL() throws { | ||
let requestToken = "qwertyuiop" | ||
let redirectURL = try XCTUnwrap(URL(string: "https://my.domain.com/auth/callback")) | ||
let expectedURL = baseURL | ||
.appendingPathComponent("authenticate") | ||
.appendingPathComponent(requestToken) | ||
.appendingQueryItem(name: "redirect_to", value: redirectURL.absoluteString) | ||
|
||
let url = builder.authenticateURL(with: requestToken, redirectURL: redirectURL) | ||
|
||
XCTAssertEqual(url, expectedURL) | ||
} | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
Tests/TMDbTests/Mocks/Authentication/AuthenticateURLMockBuilder.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,40 @@ | ||
// | ||
// AuthenticateURLMockBuilder.swift | ||
// TMDb | ||
// | ||
// Copyright © 2024 Adam Young. | ||
// | ||
// 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. | ||
// | ||
|
||
import Foundation | ||
@testable import TMDb | ||
|
||
final class AuthenticateURLMockBuilder: AuthenticateURLBuilding { | ||
|
||
var authenticateURLResult: URL = .init(string: "https://some.domain.com/authenticate")! | ||
private(set) var lastRequestToken: String? | ||
private(set) var lastRedirectURL: URL? | ||
|
||
func authenticateURL(with requestToken: String) -> URL { | ||
authenticateURL(with: requestToken, redirectURL: nil) | ||
} | ||
|
||
func authenticateURL(with requestToken: String, redirectURL: URL?) -> URL { | ||
lastRequestToken = requestToken | ||
lastRedirectURL = redirectURL | ||
|
||
return authenticateURLResult | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.