SessionAuthAgent Class
Creates an instance of SessionAuthAgent object
Auth agent handles low level implementation of authorization workflow.
By providing a login and a password in the authInfo object, the
auth agent will try to create a session:
var SessionAuthAgent({login: "admin", password: "publish"});
The session auth agent is also able to reuse an existing session, to do that it needs to receive an object with the session info:
var new SessionAuthAgent({
name: "eZSESSID",
identifier: "sessionidentifier",
href: "/api/ezp/v2/users/session/sessionidentifier",
csrfToken: "longCsrfToken",
});
Constructor
SessionAuthAgent
-
authInfo -
[storage=LocalStorage]
Parameters:
-
authInfoObjectobject literal containg the credentials (
loginandpassword) or the session info of an already existing one (name,identifier,hrefandcsrfToken)-
loginStringuser login
-
passwordStringuser password
-
nameStringname of the session
-
identifierStringidentifier of the session
-
hrefStringrefresh resource URI for the session
-
csrfTokenStringCSRF Token
-
-
[storage=LocalStorage]StorageAbstraction optionalstorage to be used. By default a LocalStorage will be utilized
Item Index
Methods
Methods
_resetStorage
()
protected
Resets the storage associated with this auth agent
_storeSessionInfo
-
session
Stores the session information in the storage
Parameters:
-
sessionObjectan object describing the session
-
nameStringthe name of the session
-
identifierStringthe identifier of the session
-
hrefStringthe resource uri to refresh the session
-
csrfTokenStringthe CSRF Token associated with the session
-
authenticateRequest
-
request -
done
Hook to allow the modification of any request, for authentication purposes, before sending it out to the backend
Parameters:
-
requestRequest -
doneFunction
ensureAuthentication
-
done
Called every time a new request cycle is started, to ensure those requests are correctly authenticated.
A cycle may contain one or more queued up requests
Parameters:
-
doneFunctionCallback function, which is to be called by the implementation to signal the authentication has been completed.
isLoggedIn
-
callback
Checks that the current user is still logged in. To be considered as
logged in, the storage should have a session id and the refresh calls
should be successful.
If the storage does not contain any session info, the callback is called
with true as its first argument, otherwise, the callback is called
with the error and result from UserService.refreshSession.
Parameters:
-
callbackFunction
logIn
-
callback
Tries to log in in the REST API. If the storage already contains a session id, first it tries to log out before doing the log in.
Parameters:
-
callbackFunction
logOut
-
done
Log out. If the client did not logged in yet, the callback is called with
false and true as arguments, otherwise the callback is called with the
error and the result from userService.deleteSession.
Parameters:
-
doneFunction
setCAPI
-
CAPI
Set the instance of the CAPI to be used by the agent
Parameters:
-
CAPICAPIcurrent instance of the CAPI object
setCredentials
-
credentials
Set the credentials
Parameters:
-
credentialsObject-
loginString -
passwordString
-
Properties
_CAPI
CAPI
protected
The CAPI instance. It is set by the call to setCAPI() done while instantiating the CAPI.
_login
String
protected
The login
Default: ""
_password
String
protected
The password
Default: ""
_storage
StorageAbstraction
protected
The storage to use to store the session info.
Default: LocalStorage
Constant to be used as storage key for the sessionName
Constant to be used as storage key for the sessionId
Constant to be used as storage key for the sessionHref
Constant to be used as storage key for the csrfToken
