Swiftpack.co - Package - nodes-vapor/nodes-sso

Nodes SSO 🔑

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

📦 Installation

Add NodesSSO to the package dependencies (in your Package.swift file):

dependencies: [
    ...,
    .package(url: "https://github.com/nodes-vapor/nodes-sso.git", from: "1.0.0-rc")
]

as well as to your target (e.g. "App"):

targets: [
    ...
    .target(
        name: "App",
        dependencies: [... "NodesSSO" ...]
    ),
    ...
]

Install resources

Copy the NodesSSO folders from Resources/Views and Public from this repo and paste them into your project into the same directories. You can download this repo as a zip and then move the files into the mentioned directories.

🚀 Getting started

First make sure that you've imported NodesSSO everywhere it's needed:

import NodesSSO

Adding the provider

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    try services.register(NodesSSOProvider<MyNodesSSOAuthenticatableUser>(config: NodesSSOConfig(
        projectURL: "https://myproject.com",
        redirectURL: "https://url-for-sso.com",
        salt: "MY-SECRET-HASH-FOR-SSO",
        environment: env
    )))
}

There are also parameters for setting the routes that should enable SSO in your project. Have a look at the signature of NodesSSOConfig for more information.

Adding the SSO routes

Make sure to add the relevant Nodes SSO routes, e.g. in your configure.swift or routes.swift:

services.register(Router.self) { container -> EngineRouter in
    let router = EngineRouter.default()
    try router.useNodesSSORoutes(MyNodesSSOAuthenticatableUser.self, on: container)
    return router
}

Adding the Leaf tag

Using a shared Leaf tag config

This package supports using a shared Leaf tag config which removes the task of registering the tags from the consumer of this package. Please see this description if you want to use this.

Manually registering the Leaf tag(s)

In order to render embed the SSO button, you will need to add the NodesSSO Leaf tag:

public func configure(_ config: inout Config, _ env: inout Environment, _ services: inout Services) throws {
    services.register { _ -> LeafTagConfig in
        var tags = LeafTagConfig.default()
        tags.use(NodesSSOConfigTag(), as: "nodessso:config")
        return tags
    }
}

Embedding the SSO button

On the page you want the NodesSSO button to appear, embed the sso-button leaf file:

#embed("NodesSSO/sso-button")

Conforming to NodesSSOAuthenticatable

The NodesSSOProvider is generic and requires a type that conforms to NodesSSOAuthenticatable. This protocol has one method that gets called when the SSO has finnished successfully:

public static func authenticated(_ user: AuthenticatedUser, req: Request) -> Future<Response>

Given this AuthenticatedUser the implementer can then look up the email and create the user if it doesn't exist, or if it does, log the user in automatically.

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Steffen.

📄 License

This package is open-sourced software licensed under the MIT license

Github

link
Stars: 5
Help us keep the lights on

Used By

Total: 0

Releases

1.0.0-rc.1 - Nov 1, 2018

Changed

  • Swift bumped to 4.2
  • Aligned with community guidelines on how to register routes

Fixed

  • Query parameters are now being passed on when logging in (https://github.com/nodes-vapor/nodes-sso/issues/15)

1.0.0-beta.2 - Sep 4, 2018

Changed

  • rename imageUrl to imageURL

1.0.0-beta.1 - Jul 6, 2018

Changed

  • Rewritten to support Vapor 3.

0.7.0 - Apr 24, 2018

Changed

  • upgrade to AdminPanelProvider 0.7.0 to support custom user types while keeping the old syntax working.

Example of using your own custom user (e.g. Person):

try addProvider(AdminPanelNodesSSO.CustomUserProvider<Person>.self)

Make sure to conform your user to SSOUserType.

0.6.0 - Apr 24, 2018

Changed

  • Update to Admin Panel 0.6.0 + Swift 4.1