Giter Club home page Giter Club logo

nodes-sso's Introduction

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")
]

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

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.useNodesSSOLeafTags()
        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.

๐Ÿ“„ License

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

nodes-sso's People

Contributors

balestrapatrick avatar brettrtoomey avatar casperhr avatar cweinberger avatar emarashliev avatar martinlasek avatar rasmusebbesen avatar siemensikkema avatar steffendsommer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nodes-sso's Issues

Logging in and out is inconsistent

Logging in and out using SSO causes login to sporadically fail.

Upon failing no toast is shown. The user is left with the login form.

Add AdminPanelProvider automatically

I discovered that the order in which the admin panel provider and the sso provider get added matters (sso comes last). How about adding the admin panel provider from inside the SSO one? That way only one provider has to be added in apps the problem of order of adding them is avoided.

@steffendsommer @BrettRToomey

Align config file name with repo name

The repository is named admin-panel-nodes-sso and the config file is named adminpanel-sso-nodes.json. It just happened to me that I switch the places and got it working after a second look at how the config file must be named.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.