Skip to content

Commit 8fae658

Browse files
committed
Rename JSONDictionary to OAuth2JSON
This makes it possible to include the OAuth2 sources in another project that may already have a definition for "JSONDictionary". Such compatibility is needed to build frameworks that need to include the source files of OAuth2 in order to be distributable.
1 parent ed681e1 commit 8fae658

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

OAuth2/OAuth2.swift

+6-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public enum OAuth2Error: Int {
3131
case AuthorizationError
3232
}
3333

34-
public typealias JSONDictionary = [String: AnyObject]
34+
public typealias OAuth2JSON = [String: AnyObject]
3535

3636

3737
/**
@@ -40,7 +40,7 @@ public typealias JSONDictionary = [String: AnyObject]
4040
public class OAuth2
4141
{
4242
/** Settings, as set upon initialization. */
43-
let settings: JSONDictionary
43+
let settings: OAuth2JSON
4444

4545
/** The client id. */
4646
public let clientId: String
@@ -69,7 +69,7 @@ public class OAuth2
6969
public var accessTokenExpiry: NSDate?
7070

7171
/** Closure called on successful authentication on the main thread. */
72-
public var onAuthorize: ((parameters: JSONDictionary) -> Void)?
72+
public var onAuthorize: ((parameters: OAuth2JSON) -> Void)?
7373

7474
/** When authorization fails (if error is not nil) or is cancelled, this block is executed on the main thread. */
7575
public var onFailure: ((error: NSError?) -> Void)?
@@ -104,7 +104,7 @@ public class OAuth2
104104

105105
MITREid: https://github.com/mitreid-connect/
106106
*/
107-
public init(settings: JSONDictionary) {
107+
public init(settings: OAuth2JSON) {
108108
self.settings = settings
109109

110110
if let cid = settings["client_id"] as? String {
@@ -249,7 +249,7 @@ public class OAuth2
249249
NSException(name: "OAuth2AbstractClassUse", reason: "Abstract class use", userInfo: nil).raise()
250250
}
251251

252-
func didAuthorize(parameters: JSONDictionary) {
252+
func didAuthorize(parameters: OAuth2JSON) {
253253
callOnMainThread() {
254254
self.onAuthorize?(parameters: parameters)
255255
self.afterAuthorizeOrFailure?(wasFailure: false, error: nil)
@@ -307,7 +307,7 @@ public class OAuth2
307307
:returns: An NSError instance with the "best" localized error key and all parameters in the userInfo dictionary;
308308
domain "OAuth2ErrorDomain", code 600
309309
*/
310-
class func errorForAccessTokenErrorResponse(params: JSONDictionary) -> NSError {
310+
class func errorForAccessTokenErrorResponse(params: OAuth2JSON) -> NSError {
311311
var message = ""
312312

313313
// "error_description" is optional, we prefer it if it's present

OAuth2/OAuth2CodeGrant.swift

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class OAuth2CodeGrant: OAuth2
3434
/** The receiver's long-time refresh token. */
3535
public var refreshToken = ""
3636

37-
public override init(settings: JSONDictionary) {
37+
public override init(settings: OAuth2JSON) {
3838
if let token = settings["token_uri"] as? String {
3939
tokenURL = NSURL(string: token)
4040
}
@@ -150,10 +150,10 @@ public class OAuth2CodeGrant: OAuth2
150150
/**
151151
Parse the NSData object returned while exchanging the code for a token in `exchangeCodeForToken`.
152152

153-
:returns: A JSONDictionary, which is usually returned upon token exchange and may contain additional information
153+
:returns: A OAuth2JSON, which is usually returned upon token exchange and may contain additional information
154154
*/
155-
func parseTokenExchangeResponse(data: NSData, error: NSErrorPointer) -> JSONDictionary? {
156-
if let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: error) as? JSONDictionary {
155+
func parseTokenExchangeResponse(data: NSData, error: NSErrorPointer) -> OAuth2JSON? {
156+
if let json = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: error) as? OAuth2JSON {
157157
if let access = json["access_token"] as? String {
158158
accessToken = access
159159
}

OAuth2/OAuth2CodeGrantFacebook.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import Foundation
2727
*/
2828
public class OAuth2CodeGrantFacebook: OAuth2CodeGrant
2929
{
30-
override func parseTokenExchangeResponse(data: NSData, error: NSErrorPointer) -> JSONDictionary? {
30+
override func parseTokenExchangeResponse(data: NSData, error: NSErrorPointer) -> OAuth2JSON? {
3131
if let str = NSString(data: data, encoding: NSUTF8StringEncoding) as? String {
3232
let query = self.dynamicType.paramsFromQuery(str)
3333
if let access = query["access_token"] {

0 commit comments

Comments
 (0)