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,
});
import React, { Component } from 'react';
class App extends Component {
state = {
loggedIn: false,
error: null,
};
componentDidMount() {
this.authenticate();
}
authenticate = async () => {
try {
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
:
{
clientId: "...",
redirectUri: window.location.origin,
restorePathAfterLogin: true,
onRestorePath: function(path) { },
autoRedirectToLogin: true,
redirectUri: "...",
authorizeUrl: "..."
maxClockSkew: 600
autoTokenRenewalBuffer: 120
}