1.1.0 • Published 7 years ago
flux-login-helper v1.1.0
flux-login-helper
Helpers for doing the OIDC Authentication Code flow with Flux.io.
Example
var FluxSdk = require("flux-sdk-node");
var LoginHelper = require("flux-login-helper");
var sdk = new FluxSdk("your_client_id", {
clientSecret: "your_client_secret",
redirectUri: "https://your.app/auth_callback",
};
/* Somewhere in your app... */
function userIsUnauthedHandler(request, response) {
var helper = new LoginHelper(sdk);
/* Redirect the user to Flux for authentication. */
response.writeHead(303, {"Location": helper.getAuthorizeUrl()});
response.end();
}
/* Setup the authentication callback route. */
app.addRoute("/auth_callback", "GET", function(request, response) {
LoginHelper.OIDCResponseHandler(request, response)
.then(function(credentials) {
/* do something e.g. get a Flux user object */
var user = sdk.getUser(credentials);
});
});
Usage
Each instance of LoginHelper is good for one authentication flow (request and response). The static method LoginHelper.OIDCResponseHandler keeps a registry of LoginHelper instances so that the authentication callback is paired with the correct initial request.
Methods
Static methods:
OIDCResponseHandler(request, response) -> Promise(credentials)
: Use this at the/auth_callback
route (or equivalent) in your app to get the authed user's credentials.setLogLevel(level)
: Sets the log level offlux-login-helper
and all its dependencies.
Instance methods:
#getAuthorizeUrl()
: Get a Flux authorization url to which you should redirect the unauthed user.#exchangeCredentials()
: Given a query object containing the parameters of the auth code response from Flux, makes the token request. You should not need to call this directly.#loginLocal() -> Promise(credentials)
: Locally runs a complete auth code flow login. Useful for terminal applications where you expect only one user.