Skip to content

Commit

Permalink
Merge pull request #13 from vapor-community/develop
Browse files Browse the repository at this point in the history
Updated project for Vapor w/ Swift NIO
  • Loading branch information
calebkleveter authored Apr 2, 2018
2 parents 8b05721 + 0761a53 commit b385dcb
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 47 deletions.
87 changes: 48 additions & 39 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,121 +1,130 @@
{
"object": {
"pins": [
{
"package": "Async",
"repositoryURL": "https://github.com/vapor/async.git",
"state": {
"branch": null,
"revision": "76ed7841b32dcc47168e8d9040ba03c024224d0c",
"version": "1.0.0-rc.1.1"
}
},
{
"package": "Console",
"repositoryURL": "https://github.com/vapor/console.git",
"state": {
"branch": null,
"revision": "26812edd1d4af8129d194ee25483159b92fed4d5",
"version": "3.0.0-rc.1"
"revision": "273cf2ed1f4daba88a452494c342020171d8c7b8",
"version": "3.0.0-rc.2.2"
}
},
{
"package": "Core",
"repositoryURL": "https://github.com/vapor/core.git",
"state": {
"branch": null,
"revision": "0dd54c6e369f575a13f2c9964609b6c7d2dab909",
"version": "3.0.0-rc.1.0.1"
"revision": "225aff2b69049f2a4d9a4aae71d27ba7fb083032",
"version": "3.0.1"
}
},
{
"package": "Crypto",
"repositoryURL": "https://github.com/vapor/crypto.git",
"state": {
"branch": null,
"revision": "e5dbff5eac700fe925f95a4e6eee5424f609d0d6",
"version": "3.0.0-rc.1.1.1"
"revision": "4c7acb4fbf1720682275f0ef543474c951d84a09",
"version": "3.0.0-rc.3"
}
},
{
"package": "DatabaseKit",
"repositoryURL": "https://github.com/vapor/database-kit.git",
"state": {
"branch": null,
"revision": "5f247a63f392d260cc7c8e9b916131a67f73dbe4",
"version": "1.0.0-rc.1"
"revision": "9e77b5b95e3f1f141abdf75d6123f591971162cd",
"version": "1.0.0-rc.2.2.1"
}
},
{
"package": "Engine",
"repositoryURL": "https://github.com/vapor/engine.git",
"state": {
"branch": null,
"revision": "e12531d2b37895d21cd8b8d13ad930fa85217e9e",
"version": "3.0.0-rc.1.0.1"
"revision": "4846ea9abeb04863f82f618ee8cb22650a82ae3c",
"version": "3.0.0-rc.2.1.1"
}
},
{
"package": "Routing",
"repositoryURL": "https://github.com/vapor/routing.git",
"state": {
"branch": null,
"revision": "8210d28691a11d0d27b7a0b32117d7fd81099916",
"version": "3.0.0-rc.1"
"revision": "2fc1d4de22a54848b35ad17b3e7f7816f19ebf90",
"version": "3.0.0-rc.2"
}
},
{
"package": "Service",
"repositoryURL": "https://github.com/vapor/service.git",
"state": {
"branch": null,
"revision": "90426d62cf1b028c0eef8285cb0293b527e45393",
"version": "1.0.0-rc.1"
"revision": "02205a16a3f4714a08836529f5a868c2ce256719",
"version": "1.0.0-rc.2.2"
}
},
{
"package": "Sockets",
"repositoryURL": "https://github.com/vapor/sockets.git",
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "738f3ebf3ebb8ea886d5dd8588dd46a54f66af1c",
"version": "3.0.0-rc.1"
"revision": "a0b7f646fba61402da384b3202f54c27debb5e13",
"version": "1.3.1"
}
},
{
"package": "TemplateKit",
"repositoryURL": "https://github.com/vapor/template-kit.git",
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "cda3174c5e029526a5b11b19fcfd83bd65b6876a",
"version": "1.0.0-rc.1.1"
"revision": "ea006b6368dbd9dbfd297deb6ddb3f070b72d043",
"version": "1.0.1"
}
},
{
"package": "TLS",
"repositoryURL": "https://github.com/vapor/tls.git",
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
}
},
{
"package": "TemplateKit",
"repositoryURL": "https://github.com/vapor/template-kit.git",
"state": {
"branch": null,
"revision": "cfd8cc0f06841ee15469c5fc98131e47511f8e94",
"version": "3.0.0-rc.1.0.1"
"revision": "61ed3d3b0df4c181d6b88e06b418f425978ac2af",
"version": "1.0.0-rc.2.0.3"
}
},
{
"package": "Validation",
"repositoryURL": "https://github.com/vapor/validation.git",
"state": {
"branch": null,
"revision": "683af11976a732584baf339483aa3206734c913b",
"version": "2.0.0-rc.1"
"revision": "1ce87fc2d18a8f15a491805825063c8db493a51e",
"version": "2.0.0-rc.2.1.1"
}
},
{
"package": "Vapor",
"repositoryURL": "https://github.com/vapor/vapor.git",
"state": {
"branch": null,
"revision": "d8254ba464b211ca6d465703f7f5d37eb0c95b65",
"version": "3.0.0-rc.1.1"
"revision": "5e59691ef575597aa640da76ccb9fc5ee638f2c1",
"version": "3.0.0-rc.2.2.1"
}
}
]
Expand Down
2 changes: 1 addition & 1 deletion Sources/Imperial/Helpers/Request+Imperial.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extension Request {

let token = try service.tokenPrefix + self.accessToken()

return try self.make(Client.self).get(uri, headers: [.authorization: token]).flatMap(to: Model.self, { (response) -> Future<Model> in
return try self.make(Client.self).get(uri, headers: ["Authorization": token]).flatMap(to: Model.self, { (response) -> Future<Model> in
return try model.create(from: response)
}).map(to: Model.self, { (instance) -> Model in
let session = try self.session()
Expand Down
5 changes: 3 additions & 2 deletions Sources/Imperial/Middleware/ImperialMiddleware.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ public class ImperialMiddleware: Middleware {
_ = try request.accessToken()
return try next.respond(to: request)
} catch let error as Abort {
guard let redirect = redirectPath else {
guard let redirectPath = redirectPath else {
throw error
}
return Future(request.redirect(to: redirect))
let redirect: Response = request.redirect(to: redirectPath)
return request.eventLoop.newSucceededFuture(result: redirect)
} catch let error {
throw error
}
Expand Down
9 changes: 5 additions & 4 deletions Sources/Imperial/Routing/FederatedServiceRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,18 @@ public protocol FederatedServiceRouter {

extension FederatedServiceRouter {
public func authenticate(_ request: Request)throws -> Future<Response> {
return Future(request.redirect(to: authURL))
let redirect: Response = request.redirect(to: authURL)
return request.eventLoop.newSucceededFuture(result: redirect)
}

public func configureRoutes(withAuthURL authURL: String, on router: Router) throws {
var callbackPath: String = callbackURL
if try NSRegularExpression(pattern: "^https?:\\/\\/", options: []).matches(in: callbackURL, options: [], range: NSMakeRange(0, callbackURL.utf8.count)).count > 0 {
callbackPath = URI(callbackURL).path
callbackPath = URL(string: callbackPath)?.path ?? callbackURL
}
callbackPath = callbackPath != "/" ? callbackPath : callbackURL

router.get(callbackPath.makePathComponent(), use: callback)
router.get(authURL.makePathComponent(), use: authenticate)
router.get(callbackPath, use: callback)
router.get(authURL, use: authenticate)
}
}
3 changes: 2 additions & 1 deletion Sources/Imperial/ServiceRegister.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ extension Router {
redirect redirectURL: String
)throws where OAuthProvider: FederatedService {
try self.oAuth(from: OAuthProvider.self, authenticate: authUrl, callback: callback, scope: scope) { (request, token) in
return Future(request.redirect(to: redirectURL))
let redirect: Response = request.redirect(to: redirectURL)
return request.eventLoop.newSucceededFuture(result: redirect)
}
}
}

0 comments on commit b385dcb

Please sign in to comment.