Skip to content

Commit

Permalink
Merge branch 'master' into feature/crypto-jwt
Browse files Browse the repository at this point in the history
# Conflicts:
#	LineSDK/LineSDK.xcodeproj/project.pbxproj
#	LineSDK/LineSDKObjCInterfaceTests/LineSDKModelInterfaceTests.m
  • Loading branch information
onevcat committed Sep 11, 2018
2 parents 1581163 + 1b339e8 commit 296e046
Show file tree
Hide file tree
Showing 54 changed files with 186 additions and 235 deletions.
18 changes: 6 additions & 12 deletions LineSDK/LineSDK.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
4B1C44652137E0CA0094C1D4 /* JWT.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1C44642137E0CA0094C1D4 /* JWT.swift */; };
4B1C44692137E1EE0094C1D4 /* JWTHelpers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1C44682137E1EE0094C1D4 /* JWTHelpers.swift */; };
4B1C446B2137E98D0094C1D4 /* JWTCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B1C446A2137E98D0094C1D4 /* JWTCoder.swift */; };
4B2422EF2134FBE8007200C2 /* LineSDKError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2422EE2134FBE8007200C2 /* LineSDKError.swift */; };
4B2422EF2134FBE8007200C2 /* LineSDKErrorConstant.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2422EE2134FBE8007200C2 /* LineSDKErrorConstant.swift */; };
4B25A815213687A400C74B87 /* RSA.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B25A814213687A400C74B87 /* RSA.swift */; };
4B25A8172136888600C74B87 /* RSAAlgorithm.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B25A8162136888600C74B87 /* RSAAlgorithm.swift */; };
4B2D14E3212F8EDA000DD5BE /* LineSDKUserProfile.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B2D14E2212F8EDA000DD5BE /* LineSDKUserProfile.swift */; };
Expand Down Expand Up @@ -270,7 +270,7 @@
4B1C44642137E0CA0094C1D4 /* JWT.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWT.swift; sourceTree = "<group>"; };
4B1C44682137E1EE0094C1D4 /* JWTHelpers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWTHelpers.swift; sourceTree = "<group>"; };
4B1C446A2137E98D0094C1D4 /* JWTCoder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = JWTCoder.swift; sourceTree = "<group>"; };
4B2422EE2134FBE8007200C2 /* LineSDKError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineSDKError.swift; sourceTree = "<group>"; };
4B2422EE2134FBE8007200C2 /* LineSDKErrorConstant.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineSDKErrorConstant.swift; sourceTree = "<group>"; };
4B25A814213687A400C74B87 /* RSA.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSA.swift; sourceTree = "<group>"; };
4B25A8162136888600C74B87 /* RSAAlgorithm.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RSAAlgorithm.swift; sourceTree = "<group>"; };
4B2D14E2212F8EDA000DD5BE /* LineSDKUserProfile.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LineSDKUserProfile.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -568,7 +568,7 @@
4B2422ED2134FBD6007200C2 /* General */ = {
isa = PBXGroup;
children = (
4B2422EE2134FBE8007200C2 /* LineSDKError.swift */,
4B2422EE2134FBE8007200C2 /* LineSDKErrorConstant.swift */,
);
path = General;
sourceTree = "<group>";
Expand Down Expand Up @@ -1610,7 +1610,7 @@
4B2D1501212FA9EE000DD5BE /* LineSDKHexColor.swift in Sources */,
4B2D14F1212F95B3000DD5BE /* LineSDKLoginResult.swift in Sources */,
4B2D14F3212F96A7000DD5BE /* LineSDKLoginProcess.swift in Sources */,
4B2422EF2134FBE8007200C2 /* LineSDKError.swift in Sources */,
4B2422EF2134FBE8007200C2 /* LineSDKErrorConstant.swift in Sources */,
4BBEA9B0212EB03200858627 /* LineSDKLoginPermission.swift in Sources */,
4B2D14F5212F97A6000DD5BE /* LineSDKLoginManager.swift in Sources */,
);
Expand Down Expand Up @@ -1665,7 +1665,6 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.TestHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1683,7 +1682,6 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.TestHost;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down Expand Up @@ -1747,6 +1745,7 @@
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
};
Expand Down Expand Up @@ -1804,6 +1803,7 @@
SDKROOT = iphoneos;
SWIFT_COMPILATION_MODE = wholemodule;
SWIFT_OPTIMIZATION_LEVEL = "-O";
SWIFT_VERSION = 4.2;
VALIDATE_PRODUCT = YES;
VERSIONING_SYSTEM = "apple-generic";
VERSION_INFO_PREFIX = "";
Expand Down Expand Up @@ -1831,7 +1831,6 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1856,7 +1855,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.LineSDK;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand All @@ -1874,7 +1872,6 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.LineSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/TestHost";
};
Expand All @@ -1893,7 +1890,6 @@
);
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.LineSDKTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 4.2;
TARGETED_DEVICE_FAMILY = "1,2";
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/TestHost.app/TestHost";
};
Expand Down Expand Up @@ -1921,7 +1917,6 @@
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Debug;
Expand All @@ -1947,7 +1942,6 @@
PRODUCT_BUNDLE_IDENTIFIER = com.linecorp.LineSDKObjC;
PRODUCT_NAME = "$(TARGET_NAME:c99extidentifier)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 4.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
name = Release;
Expand Down
42 changes: 21 additions & 21 deletions LineSDK/LineSDK/Login/LoginProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -403,28 +403,29 @@ extension WebLoginFlow: SFSafariViewControllerDelegate {
extension String {

static func returnUri(_ parameter: LoginProcess.FlowParameters) -> String {
var universalLinkQuery = ""

var parameters: [String: Any] = [
"response_type": "code",
"sdk_ver": Constant.SDKVersion,
"client_id": parameter.channelID,
"scope": (parameter.scopes.map { $0.rawValue }).joined(separator: " "),
"otpId": parameter.otp.otpId,
"state": parameter.processID,
"redirect_uri": Constant.thirdPartyAppReturnURL,
]

if let url = parameter.universalLinkURL {
universalLinkQuery = "&optional_redirect_uri=\(url.absoluteString)"
parameters["optional_redirect_uri"] = url.absoluteString
}

var nonceQuery = ""
if let nonce = parameter.nonce {
nonceQuery = "&nonce=\(nonce)"
parameters["nonce"] = nonce
}

var botPromptQuery = ""
if let botPrompt = parameter.botPrompt {
botPromptQuery = "&bot_prompt=\(botPrompt.rawValue)"
parameters["bot_prompt"] = botPrompt.rawValue
}

let result =
"/oauth2/v2.1/authorize/consent?response_type=code&sdk_ver=\(Constant.SDKVersion)" +
"&client_id=\(parameter.channelID)&scope=\((parameter.scopes.map { $0.rawValue }).joined(separator: " "))" +
"&otpId=\(parameter.otp.otpId)&state=\(parameter.processID)&redirect_uri=\(Constant.thirdPartyAppReturnURL)" +
universalLinkQuery + nonceQuery + botPromptQuery

return result
let base = URL(string: "/oauth2/v2.1/authorize/consent")!
let encoder = URLQueryEncoder(parameters: parameters)
return encoder.encoded(for: base).absoluteString
}
}

Expand All @@ -435,18 +436,17 @@ extension URL {
"returnUri": returnUri,
"loginChannelId": flowParameters.channelID
]
let encoder = URLQueryEncoder(parameters: parameters, allowed: .urlHostAllowed)
let encoder = URLQueryEncoder(parameters: parameters)
return encoder.encoded(for: self)
}

func appendedURLSchemeQuery(_ flowParameters: LoginProcess.FlowParameters) -> URL {
let returnUri = String.returnUri(flowParameters)
let loginUrl =
"\(Constant.lineWebAuthUniversalURL)?returnUri=\(returnUri)&loginChannelId=\(flowParameters.channelID)"
let loginBase = URL(string: Constant.lineWebAuthUniversalURL)!
let loginUrl = loginBase.appendedLoginQuery(flowParameters)
let parameters = [
"loginUrl": "\(loginUrl)"
]
let encoder = URLQueryEncoder(parameters: parameters, allowed: .urlHostAllowed)
let encoder = URLQueryEncoder(parameters: parameters)
return encoder.encoded(for: self)
}
}
Expand Down
57 changes: 1 addition & 56 deletions LineSDK/LineSDK/Login/LoginProcessURLResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,6 @@

import Foundation

/// Result code from LINE app auth module
enum LineAppURLResultCode: String {
case success = "SUCCESS"
case disallowed = "DISALLOWED"
case cancelled = "CANCELLED"
case invalidParameter = "INVALIDPARAM"
case networkError = "NETWORKERROR"
case generalError = "GENERALERROR"
case loginFailure = "LOGINFAIL"
}

/// Result code from LINE web auth flow
enum LineWebURLResultError: String {
case accessDenied = "access_denied"
Expand All @@ -53,52 +42,8 @@ struct LoginProcessURLResponse {
guard let items = urlComponent.queryItems else {
throw LineSDKError.authorizeFailed(reason: .malformedRedirectURL(url: url, message: nil))
}

// If the items contains a "resultCode" key, we recognize it as response from LINE url scheme auth
// Maybe we could remove this, if server/LINE app side could unify the callback flow.
let isClientURLResponse = items.contains { $0.name == "resultCode" }

if isClientURLResponse {
try self.init(clientURL:url, queryItems: items)
} else {
try self.init(webURL: url, queryItems: items, validatingState: state)
}
}

init(clientURL url: URL, queryItems items: [URLQueryItem]) throws {
var codeString = ""
var message: String?
var token: String?
for item in items {
switch item.name {
case "resultCode": codeString = item.value ?? ""
case "resultMessage": message = item.value
case "requestToken": token = item.value
default: break
}
}

guard let code = LineAppURLResultCode(rawValue: codeString) else {
throw LineSDKError.authorizeFailed(reason: .invalidLineURLResultCode(codeString))
}

switch code {
case .success:
guard let token = token else {
throw LineSDKError.authorizeFailed(reason: .malformedRedirectURL(url: url, message: message))
}
requestToken = token
case .cancelled:
throw LineSDKError.authorizeFailed(reason: .userCancelled)
case .disallowed:
// Disallowed happens when user reject the auth in the confirm screen.
// However, here we do not make `.cancelled` and `.disallowed` distinct.
throw LineSDKError.authorizeFailed(reason: .userCancelled)
default:
throw LineSDKError.authorizeFailed(reason: .lineClientError(code: code.rawValue, message: message))
}

friendshipStatusChanged = nil
try self.init(webURL: url, queryItems: items, validatingState: state)
}

init(webURL url: URL, queryItems items: [URLQueryItem], validatingState: String) throws {
Expand Down
10 changes: 6 additions & 4 deletions LineSDK/LineSDK/Networking/Client/ParametersAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ import Foundation

struct URLQueryEncoder: RequestAdapter {
let parameters: Parameters
let allowed: CharacterSet

init(parameters: Parameters, allowed: CharacterSet = .urlQueryAllowed) {
init(parameters: Parameters) {
self.parameters = parameters
self.allowed = allowed
}

func adapted(_ request: URLRequest) throws -> URLRequest {
Expand All @@ -45,7 +43,11 @@ struct URLQueryEncoder: RequestAdapter {

func encoded(for url: URL) -> URL {
if var components = URLComponents(url: url, resolvingAgainstBaseURL: false), !parameters.isEmpty {
let percentEncodedQuery = (components.percentEncodedQuery.map { $0 + "&" } ?? "") + query(parameters, allowed: allowed)

var allowedCharacterSet = CharacterSet.urlQueryAllowed
allowedCharacterSet.remove(charactersIn: "!*'();:@&=+$,/?%#[]")

let percentEncodedQuery = (components.percentEncodedQuery.map { $0 + "&" } ?? "") + query(parameters, allowed: allowedCharacterSet)
components.percentEncodedQuery = percentEncodedQuery
return components.url ?? url
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// LineSDKError.swift
// LineSDKErrorConstant.swift
//
// Copyright (c) 2016-present, LINE Corporation. All rights reserved.
//
Expand All @@ -18,11 +18,12 @@
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKError: NSObject {
public class LineSDKErrorConstant: NSObject {
public static let errorDomain = LineSDK.LineSDKError.errorDomain
public static let cryptoErrorDomain = LineSDK.CryptoError.errorDomain

Expand Down
4 changes: 3 additions & 1 deletion LineSDK/LineSDKObjC/Login/LineSDKLoginManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKLoginManager: NSObject {
Expand Down Expand Up @@ -62,7 +64,7 @@ public class LineSDKLoginManager: NSObject {
public func application(
_ app: UIApplication,
open url: URL,
options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool
{
return _value.application(app, open: url, options: options)
}
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/LineSDKLoginManagerOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKLoginManagerOptions: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/LineSDKLoginPermission.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKLoginPermission: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/LineSDKLoginProcess.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKLoginProcess: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/LineSDKLoginResult.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKLoginResult: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/Model/LineSDKAccessToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKAccessToken: NSObject {
Expand Down
2 changes: 2 additions & 0 deletions LineSDK/LineSDKObjC/Login/Model/LineSDKAccessTokenStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objc extension NSNotification {
public static let LineSDKAccessTokenDidUpdate = Notification.Name.LineSDKAccessTokenDidUpdate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//

#if !LineSDKCocoaPods
import LineSDK
#endif

@objcMembers
public class LineSDKAccessTokenVerifyResult: NSObject {
Expand Down
Loading

0 comments on commit 296e046

Please sign in to comment.