Skip to content

Commit

Permalink
added fb auth type
Browse files Browse the repository at this point in the history
  • Loading branch information
edjiang committed May 17, 2016
1 parent 376fbb1 commit abcad67
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
10 changes: 8 additions & 2 deletions Simplicity/Helpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ class Helpers {
return urlSchemes.flatMap({closure($0) ? $0 : nil})
}

static func queryString(parts: [String: String]) -> String? {
return parts.map { $0 + "=" + $1 }.joinWithSeparator("&").stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
static func queryString(parts: [String: String?]) -> String? {
return parts.flatMap { key, value -> String? in
if let value = value {
return key + "=" + value
} else {
return nil
}
}.joinWithSeparator("&").stringByAddingPercentEncodingWithAllowedCharacters(NSCharacterSet.URLQueryAllowedCharacterSet())
}
}

Expand Down
9 changes: 7 additions & 2 deletions Simplicity/LoginProviders/Facebook.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Facebook: OAuth2LoginProvider {
public var state = arc4random_uniform(10000000)
public var clientId: String
public var grantType: OAuth2GrantType = .Custom

public var authType: FacebookAuthType?

public var authorizationURL: NSURL {
// Auth_type is re-request since we need to ask for email scope again if
Expand All @@ -26,7 +26,7 @@ public class Facebook: OAuth2LoginProvider {
"redirect_uri": urlScheme + "://authorize",
"response_type": "token",
"scope": scopes.joinWithSeparator(" "),
"auth_type": "rerequest",
"auth_type": authType?.rawValue,
"state": String(state)]

let queryString = Helpers.queryString(query)!
Expand Down Expand Up @@ -61,4 +61,9 @@ public class Facebook: OAuth2LoginProvider {
self.urlScheme = urlScheme
self.clientId = urlScheme.substringWithRange(range)
}
}

public enum FacebookAuthType: String {
case Rerequest = "rerequest",
Reauthenticate = "reauthenticate"
}

0 comments on commit abcad67

Please sign in to comment.