Skip to content

Commit

Permalink
Merge pull request #84 from auth0/chore_swiftlint
Browse files Browse the repository at this point in the history
Added SwiftLint to project
  • Loading branch information
hzalaz authored Jan 27, 2017
2 parents 75d1ec6 + 268f606 commit d662a43
Show file tree
Hide file tree
Showing 21 changed files with 170 additions and 38 deletions.
55 changes: 55 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
disabled_rules: # rule identifiers to exclude from running
- colon
- comma
- control_statement
- missing_docs
- force_cast
- variable_name
- cyclomatic_complexity
- function_body_length
- todo
- file_length
opt_in_rules: # some rules are only opt-in
- empty_count
# Find all the available rules by running:
# swiftlint rules
included: # paths to include during linting. `--path` is ignored if present.
- Auth0
excluded: # paths to ignore during linting. Takes precedence over `included`.
- Carthage
- Pods
- Source/ExcludedFolder
- Source/ExcludedFile.swift

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
force_cast: warning # implicitly
force_try:
severity: warning # explicitly
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length: 500
# they can set both implicitly with an array
type_body_length:
- 300 # warning
- 400 # error
# or they can set both explicitly
file_length:
warning: 500
error: 1200
# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 4 # only warning
max_length: # warning and error
warning: 40
error: 50
excluded: iPhone # excluded via string
variable_name:
min_length: # only min_length
error: 4 # only error
excluded: # excluded via string array
- id
- URL
- GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit)
60 changes: 60 additions & 0 deletions Auth0.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@
5F06DD741CC448B10011842B /* Frameworks */,
5F06DD751CC448B10011842B /* Headers */,
5F06DD761CC448B10011842B /* Resources */,
5B717B241E2E2696004A05A7 /* SwiftLint */,
);
buildRules = (
);
Expand All @@ -865,6 +866,7 @@
5F06DD811CC448C90011842B /* Frameworks */,
5F06DD821CC448C90011842B /* Headers */,
5F06DD831CC448C90011842B /* Resources */,
5B717B251E2E26B9004A05A7 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -922,6 +924,7 @@
5F23E6B51D4ACA7100C3F2D9 /* Frameworks */,
5F23E6B61D4ACA7100C3F2D9 /* Headers */,
5F23E6B71D4ACA7100C3F2D9 /* Resources */,
5B717B261E2E26C4004A05A7 /* SwiftLint */,
);
buildRules = (
);
Expand All @@ -940,6 +943,7 @@
5F23E6F21D4B87F000C3F2D9 /* Frameworks */,
5F23E6F31D4B87F000C3F2D9 /* Headers */,
5F23E6F41D4B87F000C3F2D9 /* Resources */,
5B717B271E2E26CE004A05A7 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -1128,6 +1132,62 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
5B717B241E2E2696004A05A7 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nfi";
};
5B717B251E2E26B9004A05A7 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nfi";
};
5B717B261E2E26C4004A05A7 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nfi";
};
5B717B271E2E26CE004A05A7 /* SwiftLint */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = SwiftLint;
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nfi";
};
5F53F5CB1CFCDC2500476A46 /* Auth0 */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
Expand Down
18 changes: 10 additions & 8 deletions Auth0/Auth0Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct Auth0Authentication: Authentication {
self.telemetry = telemetry
}

// swiftlint:disable:next function_parameter_count
func login(usernameOrEmail username: String, password: String, multifactorCode: String?, connection: String, scope: String, parameters: [String: Any]) -> Request<Credentials, AuthenticationError> {
let resourceOwner = URL(string: "/oauth/ro", relativeTo: self.url)!
var payload: [String: Any] = [
Expand All @@ -45,7 +46,7 @@ struct Auth0Authentication: Authentication {
"connection": connection,
"grant_type": "password",
"scope": scope,
"client_id": self.clientId,
"client_id": self.clientId
]
payload["mfa_code"] = multifactorCode
parameters.forEach { key, value in payload[key] = value }
Expand All @@ -71,7 +72,7 @@ struct Auth0Authentication: Authentication {
"email": email,
"password": password,
"connection": connection,
"client_id": self.clientId,
"client_id": self.clientId
]
payload["username"] = username
payload["user_metadata"] = userMetadata
Expand All @@ -90,6 +91,7 @@ struct Auth0Authentication: Authentication {
return Request(session: session, url: resetPassword, method: "POST", handle: noBody, payload: payload, logger: self.logger, telemetry: self.telemetry)
}

// swiftlint:disable:next function_parameter_count
func signUp(email: String, username: String? = nil, password: String, connection: String, userMetadata: [String: Any]?, scope: String, parameters: [String: Any]) -> ConcatRequest<DatabaseUser, Credentials, AuthenticationError> {
let first = createUser(email: email, username: username, password: password, connection: connection, userMetadata: userMetadata)
let second = login(usernameOrEmail: email, password: password, connection: connection, scope: scope, parameters: parameters)
Expand All @@ -101,7 +103,7 @@ struct Auth0Authentication: Authentication {
"email": email,
"connection": connection,
"send": type.rawValue,
"client_id": self.clientId,
"client_id": self.clientId
]
if case .WebLink = type , !parameters.isEmpty {
payload["authParams"] = parameters
Expand All @@ -116,7 +118,7 @@ struct Auth0Authentication: Authentication {
"phone_number": phoneNumber,
"connection": connection,
"send": type.rawValue,
"client_id": self.clientId,
"client_id": self.clientId
]
let start = URL(string: "/passwordless/start", relativeTo: self.url)!
return Request(session: session, url: start, method: "POST", handle: noBody, payload: payload, logger: self.logger, telemetry: self.telemetry)
Expand All @@ -138,7 +140,7 @@ struct Auth0Authentication: Authentication {
"access_token": token,
"connection": connection,
"scope": scope,
"client_id": self.clientId,
"client_id": self.clientId
]
parameters.forEach { key, value in payload[key] = value }
let accessToken = URL(string: "/oauth/access_token", relativeTo: self.url)!
Expand All @@ -147,7 +149,7 @@ struct Auth0Authentication: Authentication {

func tokenExchange(withParameters parameters: [String: Any]) -> Request<Credentials, AuthenticationError> {
var payload: [String: Any] = [
"client_id": self.clientId,
"client_id": self.clientId
]
parameters.forEach { payload[$0] = $1 }
let token = URL(string: "/oauth/token", relativeTo: self.url)!
Expand All @@ -159,7 +161,7 @@ struct Auth0Authentication: Authentication {
"code": code,
"code_verifier": codeVerifier,
"redirect_uri": redirectURI,
"grant_type": "authorization_code",
"grant_type": "authorization_code"
])
}

Expand All @@ -176,7 +178,7 @@ struct Auth0Authentication: Authentication {
func delegation(withParameters parameters: [String : Any]) -> Request<[String : Any], AuthenticationError> {
var payload: [String: Any] = [
"client_id": self.clientId,
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer",
"grant_type": "urn:ietf:params:oauth:grant-type:jwt-bearer"
]
parameters.forEach { payload[$0] = $1 }
let delegation = URL(string: "/delegation", relativeTo: self.url)!
Expand Down
1 change: 0 additions & 1 deletion Auth0/Auth0Error.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,4 @@ public protocol Auth0Error: Error {

/// The code of the error as a String
var code: String { get }

}
3 changes: 2 additions & 1 deletion Auth0/Authentication.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public protocol Authentication: Trackable, Loggable {
- returns: authentication request that will yield Auth0 User Credentials
- seeAlso: Credentials
*/
// swiftlint:disable:next function_parameter_count
func login(usernameOrEmail username: String, password: String, multifactorCode: String?, connection: String, scope: String, parameters: [String: Any]) -> Request<Credentials, AuthenticationError>

/**
Expand Down Expand Up @@ -220,6 +221,7 @@ public protocol Authentication: Trackable, Loggable {

- returns: an authentication request that will yield Auth0 user credentials after creating the user.
*/
// swiftlint:disable:next function_parameter_count
func signUp(email: String, username: String?, password: String, connection: String, userMetadata: [String: Any]?, scope: String, parameters: [String: Any]) -> ConcatRequest<DatabaseUser, Credentials, AuthenticationError>

/**
Expand Down Expand Up @@ -500,7 +502,6 @@ public extension Authentication {
return self.login(usernameOrEmail: username, password: password, realm: realm, audience: audience, scope: scope)
}


/**
Creates a user in a Database connection

Expand Down
2 changes: 1 addition & 1 deletion Auth0/AuthenticationError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ extension AuthenticationError: CustomNSError {
public var errorUserInfo: [String : Any] {
return [
NSLocalizedDescriptionKey: self.description,
AuthenticationError.infoKey: self,
AuthenticationError.infoKey: self
]
}
}
2 changes: 1 addition & 1 deletion Auth0/ControllerModalPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ struct ControllerModalPresenter {
init(rootViewController: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) {
self.rootViewController = rootViewController
}

func present(_ controller: UIViewController) {
topViewController?.present(controller, animated: true, completion: nil)
}
Expand Down
1 change: 1 addition & 0 deletions Auth0/Identity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class Identity: NSObject, JSONObjectPayload {
return "<identity: \(identifier) provider: \(provider) connection: \(connection)>"
}

// swiftlint:disable:next function_parameter_count
public required init(identifier: String, provider: String, connection: String, social: Bool, profileData: [String: Any], accessToken: String?, expiresIn: Date?, accessTokenSecret: String?) {
self.identifier = identifier
self.provider = provider
Expand Down
4 changes: 2 additions & 2 deletions Auth0/ManagementError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class ManagementError: Auth0Error, CustomStringConvertible {
- seeAlso: `code` & `description` properties
*/
public let info: [String: Any]

/**
Creates a Auth0 Management API error when the request's response is not JSON

Expand Down Expand Up @@ -89,7 +89,7 @@ extension ManagementError: CustomNSError {
public var errorUserInfo: [String : Any] {
return [
NSLocalizedDescriptionKey: self.description,
ManagementError.infoKey: self,
ManagementError.infoKey: self
]
}
}
8 changes: 4 additions & 4 deletions Auth0/OAuth2Grant.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ struct PKCE: OAuth2Grant {
self.init(authentication: authentication, redirectURL: redirectURL, verifier: generator.verifier, challenge: generator.challenge, method: generator.method, responseType: reponseType, nonce: nonce)
}

// swiftlint:disable:next function_parameter_count
init(authentication: Authentication, redirectURL: URL, verifier: String, challenge: String, method: String, responseType: [ResponseType], nonce: String? = nil) {
self.authentication = authentication
self.redirectURL = redirectURL
Expand All @@ -80,7 +81,7 @@ struct PKCE: OAuth2Grant {

var newDefaults: [String: String] = [
"code_challenge": challenge,
"code_challenge_method": method,
"code_challenge_method": method
]

if let nonce = nonce {
Expand All @@ -94,8 +95,7 @@ struct PKCE: OAuth2Grant {
guard
let code = values["code"]
else {
let data = try! JSONSerialization.data(withJSONObject: values, options: [])
let string = String(data: data, encoding: .utf8)
let string = "No code found in parameters \(values)"
return callback(.failure(error: AuthenticationError(string: string)))
}
guard validate(responseType: self.responseType, token: values["id_token"], nonce: self.defaults["nonce"]) else {
Expand All @@ -105,7 +105,7 @@ struct PKCE: OAuth2Grant {
self.authentication
.tokenExchange(withCode: code, codeVerifier: verifier, redirectURI: redirectURL.absoluteString)
.start { result in
// FIXME: Special case for PKCE when the correct method for token endpoint authentication is not set (it should be None)
// Special case for PKCE when the correct method for token endpoint authentication is not set (it should be None)
if case .failure(let cause as AuthenticationError) = result , cause.description == "Unauthorized" {
let error = WebAuthError.pkceNotAllowed("Please go to 'https://manage.auth0.com/#/applications/\(clientId)/settings' and make sure 'Client Type' is 'Native' to enable PKCE.")
callback(Result.failure(error: error))
Expand Down
4 changes: 2 additions & 2 deletions Auth0/Profile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import Foundation


/**
Auth0 normalized user profile returned by Auth0

Expand Down Expand Up @@ -61,6 +60,7 @@ public class Profile: NSObject, JSONObjectPayload {
return self["app_metadata"] as? [String: Any] ?? [:]
}

// swiftlint:disable:next function_parameter_count
required public init(id: String, name: String, nickname: String, pictureURL: URL, createdAt: Date, email: String?, emailVerified: Bool, givenName: String?, familyName: String?, attributes: [String: Any], identities: [Identity]) {
self.id = id
self.name = name
Expand Down Expand Up @@ -112,4 +112,4 @@ private func date(from string: String) -> Date? {
return formatter.date(from: string)
}
return Date(timeIntervalSince1970: interval)
}
}
7 changes: 4 additions & 3 deletions Auth0/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public struct Request<T, E: Auth0Error>: Requestable {
let logger: Logger?
let telemetry: Telemetry

// swiftlint:disable:next function_parameter_count
init(session: URLSession, url: URL, method: String, handle: @escaping (Response<E>, Callback) -> (), payload: [String: Any] = [:], headers: [String: String] = [:], logger: Logger?, telemetry: Telemetry) {
self.session = session
self.url = url
Expand All @@ -62,8 +63,8 @@ public struct Request<T, E: Auth0Error>: Requestable {
var request: URLRequest {
let request = NSMutableURLRequest(url: url)
request.httpMethod = method
if !payload.isEmpty {
request.httpBody = try! JSONSerialization.data(withJSONObject: payload, options: [])
if !payload.isEmpty, let httpBody = try? JSONSerialization.data(withJSONObject: payload, options: []) {
request.httpBody = httpBody
#if DEBUG
URLProtocol.setProperty(payload, forKey: ParameterPropertyKey, in: request)
#endif
Expand Down Expand Up @@ -91,7 +92,7 @@ public struct Request<T, E: Auth0Error>: Requestable {
logger?.trace(response: response, data: data)
}
handler(Response(data: data, response: response, error: error), callback)
})
})
task.resume()
}

Expand Down
Loading

0 comments on commit d662a43

Please sign in to comment.