oc-plugin-authenticate
oc-plugin-authenticate allows any OC component to authenticate requests.
Authentication
An OC appication using this plugin may authenticate any request to help control application flow and protect sensitive data.
Usage:
moduleexports { contextplugins;};
After authenticating, you will receive either an error or a value using the callback pattern. The value will contain a user
object, and a token
string.
-
The
user
object will contain any claims or details provided within your authentication token. -
The
token
string will be the authentication token provided in the original request and can be used to ensure further interactions with your OC component (eg. via AJAX calls usinggetData
) are authenticated (see: Persisting authentication).
The authenticate method also has a few overloads which allows you to influence the authenticate algorithm if necessary.
contextplugins;contextplugins;contextplugins;
strategy
: string
Allows you to specify what strategy to use when authenticating. The value must refer to one of the strategies provided when the plugin was registered within the oc-registry.
options
: object
Will override something or another UPDATE THIS PART PLEASE!
Persisting authentication
When making getData
calls within your component, sending headers is not possible by design as it causes the browser to make a pre-flight request. Therefore, you must provide the token as a simple oc parameter to ensure your application can authenticate your XHR request.
We recommend that you reserve and use the access_token
parameter to send the access_token because most oc-authentication-strategy
implementations will expect this parameter by default.
React Template example:
Component { superprops; } { const access_token = thisprops; const params = ...data // we use access_token to ensure // that we can authenticate // our requests. access_token ; thisprops; } { return <button onClick= this>GO!</button> }
Registry setup
For more information about integrating OC plugins click here.
When registering, the plugin must provide at least one strategy
and must specify the defaultStrategy
. Optionally, you may provide default options
that will be provided to your strategy function.
const configuration = ... ;const registry = configuration;const twitterAuth = ;const internalAuth = ; registry; registrystartcallback;