Giter Club home page Giter Club logo

nexus-mods-sso-integration-demo's Introduction

sso-integration-demo

A simple page to demonstrate the SSO integration using simple JS for a website.

Basic SSO usage

Connect to the SSO service, via a websocket client:

window.socket = new WebSocket("wss://sso.nexusmods.com");

Once connected, retrieve the request ID and connection_token used on the previous connection.

// retrieve previous uuid and token
uuid = sessionStorage.getItem("uuid");
token = sessionStorage.getItem("connection_token");

Or, if this is the first connection, just generate a random uuid, a token is not needed for first connection

uuid = uuidv4();
token = null;
sessionStorage.setItem('uuid', uuid);
var data = {
    id: uuid,
    token: token,
    protocol: 2
};

// Send the request
socket.send(JSON.stringify(data));

This has informed the SSO server that we are ready to received the user's approval. Once the request is sent, the SSO will send a message back with the connection_token mentioned above - this is only used on subsequent connections (usually due to disconnects and network errors). The response from the SSO will look something like this:

{"success":true,"data":{"connection_token":"X5SjO3P4i8tiBgMdYVTCh3z57ZnWVK5z"},"error":null}

The response will always contain a success attribute, along with error, to be used for error reporting.

The browser can now be opened and the authorise page can be shown.

// Open the browser window, using the uuid and your application's reference
window.open("https://www.nexusmods.com/sso?id="+uuid+"&application="+application_slug);

Note: an application reference can only be generated by Nexus Mods staff. Please, contact the Community Team for further instructions.

The user will be shown an 'authorise' page, or the login page if they are not logged in. Once they have authorised the token, the API key will be sent through the websocket in the following format

{"success":true,"data":{"api_key":"VX2PMnc4T5Q3dUFmjE45WyRyZ3VkKzIvYVJiMUdick5XQU9QWHdUbFo4..."},"error":null}

This API key can be stored by the client and sent as a header for every HTTP request for the API.

nexus-mods-sso-integration-demo's People

Contributors

verenion avatar

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.