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:
-
authInfo
Objectobject literal containg the credentials (
login
andpassword
) or the session info of an already existing one (name
,identifier
,href
andcsrfToken
)-
login
Stringuser login
-
password
Stringuser password
-
name
Stringname of the session
-
identifier
Stringidentifier of the session
-
href
Stringrefresh resource URI for the session
-
csrfToken
StringCSRF 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:
-
session
Objectan object describing the session
-
name
Stringthe name of the session
-
identifier
Stringthe identifier of the session
-
href
Stringthe resource uri to refresh the session
-
csrfToken
Stringthe 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:
-
request
Request -
done
Function
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:
-
done
FunctionCallback 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:
-
callback
Function
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:
-
callback
Function
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:
-
done
Function
setCAPI
-
CAPI
Set the instance of the CAPI to be used by the agent
Parameters:
-
CAPI
CAPIcurrent instance of the CAPI object
setCredentials
-
credentials
Set the credentials
Parameters:
-
credentials
Object-
login
String -
password
String
-
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