Skip to content

Commit

Permalink
remove SwiftyJSON (#59)
Browse files Browse the repository at this point in the history
* remove dependency on SwiftyJSON
* update dependency Kitura-Session to 3.x
  • Loading branch information
Andrew-Lees11 authored and tunniclm committed Jan 16, 2018
1 parent 46a0805 commit c394d86
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Packages
.build
build
Package.resolved
.DS_Store
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/IBM-Swift/Kitura-Session.git", from: "2.0.0"),
.package(url: "https://github.com/IBM-Swift/Kitura-Session.git", from: "3.0.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
Expand Down
15 changes: 6 additions & 9 deletions Sources/Credentials/Credentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,8 @@ import Kitura
import KituraNet
import KituraSession
import LoggerAPI

import Foundation

import SwiftyJSON

// MARK Credentials

/// A pluggable framework for validating user credentials.
Expand Down Expand Up @@ -133,10 +130,10 @@ public class Credentials : RouterMiddleware {
/// - Parameter for request: The `RouterRequest` to get the URL.
/// - Returns: A String containing the URL, or nil if there is no session or the URL is not set.
public static func getRedirectingReturnTo(for request: RouterRequest) -> String? {
guard let session = request.session, session["returnTo"].type != .null else {
guard let session = request.session, session["returnTo"] != nil else {
return nil
}
return session["returnTo"].stringValue
return (session["returnTo"] as? String) ?? ""
}

/// Set the URL to which the flow will return to after successfully authenticating using a redirecting plugin.
Expand All @@ -146,7 +143,7 @@ public class Credentials : RouterMiddleware {
/// - Parameter for request: The `RouterRequest` to set the URL.
public static func setRedirectingReturnTo(_ returnTo: String, for request: RouterRequest) {
if let session = request.session {
session["returnTo"] = JSON(returnTo)
session["returnTo"] = returnTo
}
}

Expand Down Expand Up @@ -289,8 +286,8 @@ public class Credentials : RouterMiddleware {

static func restoreUserProfile(from session: SessionState) -> UserProfile? {
let sessionUserProfile = session["userProfile"]
if sessionUserProfile.type != .null {
if let dictionary = sessionUserProfile.dictionaryObject,
if sessionUserProfile != nil {
if let dictionary = sessionUserProfile as? [String:Any],
let displayName = dictionary["displayName"] as? String,
let provider = dictionary["provider"] as? String,
let id = dictionary["id"] as? String {
Expand Down Expand Up @@ -366,6 +363,6 @@ public class Credentials : RouterMiddleware {
dictionary["extendedProperties"] = userProfile.extendedProperties
}

session["userProfile"] = JSON(dictionary)
session["userProfile"] = dictionary
}
}

0 comments on commit c394d86

Please sign in to comment.