1.1.1 • Published 5 years ago
@splunkdev/cloud-auth v1.1.1
DEPRECATED - @splunkdev/cloud-auth
This package is deprecated, and is no longer being maintained.
Please use @splunkdev/cloud-auth-client for authenticating front-end web applications with Splunk Cloud Services.
The below documentation has been preserved for posterity.
Install
$ yarn add @splunkdev/cloud-auth
# or
$ npm install --save @splunkdev/cloud-auth
Usage Example
"auth": {
"clientId": "your_client_id",
}
import AuthClient from '@splunkdev/cloud-auth/AuthClient';
import { auth as authConfig } from '../config/config.json';
export default new AuthClient({
...authConfig,
redirectUri: window.location.origin, // eslint-disable-line
});
// ...
import React, { Component } from 'react';
class App extends Component {
state = {
loggedIn: false,
error: null,
};
componentDidMount() {
this.authenticate();
}
authenticate = async () => {
try {
// authClient will redirect to login page if user is not authenticated.
const loggedIn = await authClient.checkAuthentication();
this.setState({
loggedIn,
});
} catch (e) {
this.setState({
loggedIn: false,
error: e.message,
});
}
};
render() {
const { error, loggedIn } = this.state;
if (error) {
return <div>Error: {error}</div>;
}
if (!loggedIn) {
return <div>Loading...</div>;
}
return <div>My App...</div>;
}
}
Configuration
Configuration Options for AuthClient
:
{
// Client ID is used to identify the app registred with the App Registry
clientId: "...", // required
// The redirect URI is used to redirect the user back to the web app after
// login. This redirectUri must be registered with the App Registry
redirectUri: window.location.origin, // required
// If enabled, then the @splunkdev/cloud-auth lib will restore the path of the web app
// after redirecting to login page
restorePathAfterLogin: true,
// This function is called (if provided) when the user was redirected back
// from login, after the auth callback was successfully applied.
// This function can be used to integrate with third-party client-side
// routers, such as react-router intead of calling `history.replaceState`.
onRestorePath: function(path) { /* ... */ },
// If enabled, the user is automatically redirected to login page when
// the AuthClient instance is created or when checkAuthentication is called
// and the user is no already logged in.
// This is enabled by default but can be disabled by setting it to `false`.
autoRedirectToLogin: true,
// The url that is redirected to when using token.getWithRedirect.
// This must be pre-registered as part of client registration. If no redirectUri is provided, defaults to the current origin.
redirectUri: "...",
// authorizeUrl to perform the authorization flow. Defaults to Splunk authorize server.
authorizeUrl: "..."
// maxClockSkew specifies the duration buffer in seconds for token expiration
// (now > actualExpiration - maxClockSkew) will be considered expired
//
// Default value is 600
maxClockSkew: 600
// autoTokenRenewalBuffer specifies the duration buffer in seconds for token auto renewal.
// (now > actualExpiration - autoTokenRenewalBuffer) will trigger an auto renewal
//
// Default value is 120
autoTokenRenewalBuffer: 120
}
1.1.1
5 years ago
1.1.0
5 years ago
1.0.0
6 years ago
1.0.0-beta.6
6 years ago
1.0.0-beta.5
6 years ago
1.0.0-beta.4
6 years ago
1.0.0-beta.3
6 years ago
1.0.0-beta.2
6 years ago
1.0.0-beta.1
6 years ago
1.0.0-beta.0
6 years ago