Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove source application check due to not supported on iOS 13 #97

Merged
merged 2 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions LineSDK/LineSDK/General/LineSDKError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public enum LineSDKError: Error {
/// - callbackURLSchemeNotMatching: The received `URL` object while opening the app does not match the
/// defined URL scheme. Code 3005.
/// - invalidSourceApplication: The source application is invalid and cannot finish the authorization
/// process. Code 3006.
/// process. Not in use anymore from LINE SDK 5.2.4. Code 3006.
/// - malformedRedirectURL: The received `URL` object while opening the app is invalid or does not
/// contain necessary information. Code 3007.
/// - invalidLineURLResultCode: The received `URL` object while opening the app has an unknown result
Expand Down Expand Up @@ -138,7 +138,8 @@ public enum LineSDKError: Error {
/// The received `URL` object while opening the app does not match the defined URL scheme. Code 3005.
case callbackURLSchemeNotMatching

/// The source application is invalid and cannot finish the authorization process. Code 3006.
/// The source application is invalid and cannot finish the authorization process.
/// Not in use anymore from LINE SDK 5.2.4. Code 3006.
case invalidSourceApplication

/// The received `URL` object while opening the app is invalid or does not
Expand Down
14 changes: 0 additions & 14 deletions LineSDK/LineSDK/Login/LoginConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,4 @@ struct LoginConfiguration {

return true
}

/// Checks whether the `appID` is on the white list of calling back source app.
///
/// - Parameter appID: The app ID of the source app which opens current app by `open(:url:)`.
/// - Returns: `true` if `appID` is from a valid auth application.
func isValidSourceApplication(appID: String) -> Bool {
var validPrefixes = ["jp.naver", "com.apple", "com.linecorp"]
if let currentAppID = Bundle.main.bundleIdentifier {
validPrefixes.append(currentAppID)
}

let valid = validPrefixes.contains { appID.hasPrefix($0) }
return valid
}
}
3 changes: 1 addition & 2 deletions LineSDK/LineSDK/Login/LoginManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,7 @@ public class LoginManager {
guard let url = url else { return false }
guard let currentProcess = currentProcess else { return false }

let sourceApplication = options[.sourceApplication] as? String
return currentProcess.resumeOpenURL(url: url, sourceApplication: sourceApplication)
return currentProcess.resumeOpenURL(url: url)
}
}

Expand Down
11 changes: 1 addition & 10 deletions LineSDK/LineSDK/Login/LoginProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ public class LoginProcess {
webLoginFlow.start(in: presentingViewController)
}

func resumeOpenURL(url: URL, sourceApplication: String?) -> Bool {
func resumeOpenURL(url: URL) -> Bool {

let isValidUniversalLinkURL = configuration.isValidUniversalLinkURL(url: url)
let isValidCustomizeURL = configuration.isValidCustomizeURL(url: url)
Expand All @@ -248,15 +248,6 @@ public class LoginProcess {
return false
}

// For universal link callback, we can skip source application checking.
// Just do it for customize URL scheme.
if isValidCustomizeURL {
guard let sourceApp = sourceApplication, configuration.isValidSourceApplication(appID: sourceApp) else {
invokeFailure(error: LineSDKError.authorizeFailed(reason: .invalidSourceApplication))
return false
}
}

// It is the callback url we could handle, so the app switching observer should be invalidated.
appSwitchingObserver?.valid = false

Expand Down
10 changes: 0 additions & 10 deletions LineSDK/LineSDKTests/Login/LoginConfigurationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,4 @@ class LoginConfigurationTests: XCTestCase {
let result = config.isValidUniversalLinkURL(url: URL(string: "https://example.com")!)
XCTAssertEqual(result, false)
}

func testValidSourceApplication() {
let config = LoginConfiguration(channelID: "123", universalLinkURL: nil)
let results = [
"jp.naver.line",
"com.apple.hello",
"com.company.app"
].map(config.isValidSourceApplication)
XCTAssertEqual(results, [true, true, false])
}
}
2 changes: 1 addition & 1 deletion LineSDK/LineSDKTests/Login/LoginManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class LoginManagerTests: XCTestCase, ViewControllerCompatibleTest {
XCTAssertTrue(LoginManager.shared.isAuthorizing)

let urlString = "\(Constant.thirdPartyAppReturnURL)?code=123&state=\(process.processID)"
let handled = process.resumeOpenURL(url: URL(string: urlString)!, sourceApplication: "com.apple.safari")
let handled = process.resumeOpenURL(url: URL(string: urlString)!)
XCTAssertTrue(handled)
}

Expand Down