Skip to content

Commit

Permalink
Migration 0823 (#8)
Browse files Browse the repository at this point in the history
* Kitura/Kitura#675 Changes due to @escaping

* Kitura/Kitura#675 Updated Swift version

* Kitura/Kitura#697 Updated Swift version

* Kitura/Kitura#697 Swift language and Linux Foundation changes

* Kitura/Kitura#697 Updated dependencies
  • Loading branch information
shmuelk committed Aug 28, 2016
1 parent fba60e7 commit 41b12a3
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DEVELOPMENT-SNAPSHOT-2016-07-25-a
DEVELOPMENT-SNAPSHOT-2016-08-23-a
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ import PackageDescription
let package = Package(
name: "Kitura-CredentialsGoogle",
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura-Credentials.git", majorVersion: 0, minor: 26),
.Package(url: "https://github.com/IBM-Swift/Kitura-Credentials.git", majorVersion: 0, minor: 27),
]
)
11 changes: 5 additions & 6 deletions Sources/CredentialsGoogle/CredentialsGoogle.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ public class CredentialsGoogle : CredentialsPluginProtocol {
return true
}

#if os(OSX)
public var usersCache : NSCache<NSString, BaseCacheElement>?
#else
public var usersCache : Cache?
#endif


public init (clientId: String, clientSecret : String, callbackUrl : String) {
self.clientId = clientId
Expand All @@ -53,7 +48,11 @@ public class CredentialsGoogle : CredentialsPluginProtocol {
}

/// https://developers.google.com/youtube/v3/guides/auth/server-side-web-apps#Obtaining_Access_Tokens
public func authenticate (request: RouterRequest, response: RouterResponse, options: [String:OptionValue], onSuccess: (UserProfile) -> Void, onFailure: (HTTPStatusCode?, [String:String]?) -> Void, onPass: (HTTPStatusCode?, [String:String]?) -> Void, inProgress: () -> Void) {
public func authenticate (request: RouterRequest, response: RouterResponse,
options: [String:Any], onSuccess: @escaping (UserProfile) -> Void,
onFailure: @escaping (HTTPStatusCode?, [String:String]?) -> Void,
onPass: @escaping (HTTPStatusCode?, [String:String]?) -> Void,
inProgress: @escaping () -> Void) {

if let code = request.queryParameters["code"] {
var requestOptions: [ClientRequest.Options] = []
Expand Down
33 changes: 18 additions & 15 deletions Sources/CredentialsGoogle/CredentialsGoogleToken.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,27 +35,25 @@ public class CredentialsGoogleToken : CredentialsPluginProtocol {

public init () {}

#if os(OSX)
public var usersCache : NSCache<NSString, BaseCacheElement>?
#else
public var usersCache : Cache?
#endif

public func authenticate (request: RouterRequest, response: RouterResponse, options: [String:OptionValue], onSuccess: (UserProfile) -> Void, onFailure: (HTTPStatusCode?, [String:String]?) -> Void, onPass: (HTTPStatusCode?, [String:String]?) -> Void, inProgress: () -> Void) {
public func authenticate (request: RouterRequest, response: RouterResponse,
options: [String:Any], onSuccess: @escaping (UserProfile) -> Void,
onFailure: @escaping (HTTPStatusCode?, [String:String]?) -> Void,
onPass: @escaping (HTTPStatusCode?, [String:String]?) -> Void,
inProgress: @escaping () -> Void) {
if let type = request.headers["X-token-type"], type == name {
if let token = request.headers["access_token"] {
let cacheElement = usersCache!.object(forKey: token.bridge())
#if os(Linux)
if let cached = cacheElement as? BaseCacheElement {
onSuccess(cached.userProfile)
return
}
let key = NSString(string: token)
#else
if let cached = cacheElement {
onSuccess(cached.userProfile)
return
}
let key = token as NSString
#endif
let cacheElement = usersCache!.object(forKey: key)
if let cached = cacheElement {
onSuccess(cached.userProfile)
return
}

var requestOptions: [ClientRequest.Options] = []
requestOptions.append(.schema("https://"))
Expand All @@ -76,7 +74,12 @@ public class CredentialsGoogleToken : CredentialsPluginProtocol {
let name = jsonBody["name"].string {
let userProfile = UserProfile(id: id, displayName: name, provider: self.name)
let newCacheElement = BaseCacheElement(profile: userProfile)
self.usersCache!.setObject(newCacheElement, forKey: token.bridge())
#if os(Linux)
let key = NSString(string: token)
#else
let key = token as NSString
#endif
self.usersCache!.setObject(newCacheElement, forKey: key)
onSuccess(userProfile)
return
}
Expand Down

0 comments on commit 41b12a3

Please sign in to comment.