isAuthorized( ) method
- Last Updated: June 14, 2019
- 4 minute read
- OpenEdge
- Version 13.0
- Documentation
Determines if the current JSDOSession object has authorized access to the web
application specified by its serviceURI
property setting.
This method also causes an offline or
online event to fire if it detects that there has been a
change in the JSDOSession object's online state.
This method is always executed asynchronously and returns results in callbacks that you register using methods of a Promise object returned as the method value.
Return type: jQuery Promise
Applies to: progress.data.JSDOSession class
Syntax
|
Promise method signatures
jQuery Promise objects define methods that you can call to register a
callback function with a specific signature. The callback signatures depend on the method
that returns the Promise. Following are the signatures of callbacks registered by methods in
any Promise object that isAuthorized( ) returns:
Syntax:
|
- promise
- A reference to the Promise object that is returned as the value of
the
isAuthorized( )method. For more information on Promises, see the notes on Promises in the description of the progress.data.JSDOSession class. - session
- A reference to the
JSDOSessionobject on whichisAuthorized( )was called. - result
- One of the following
stringconstant values depending on theJSDOSessionauthorization or online status identified byisAuthorized( ):progress.data.Session.SUCCESS— An authentication appropriate to theJSDOSessionobject’sauthenticationModelsetting previously succeeded and is currently sufficient to give access to the web application specified by itsserviceURIsetting.progress.data.Session.AUTHENTICATION_FAILURE— An authentication appropriate to theJSDOSessionobject’sauthenticationModelsetting previously succeeded, but theJSDOSessionis no longer authorized to access its web application, for example, because the login session, established using HTTP Form authentication, has expired.progress.data.Session.LOGIN_AUTHENTICATION_REQUIRED— No successful authentication was completed for thisJSDOSessionobject (there was no login session), or if there was a login session established, theJSDOSessionhas terminated its access to its web application by logging out.Note: This value is also returned when invoking the method after a page refresh if page refresh support is not enabled for theJSDOSession. For more information, see Additional information.progress.data.Session.GENERAL_FAILURE— An error resulted from trying to contact its web application. You might find more information by consulting the info callback parameter.
The authorization status (result parameter value) is determined by whether the
JSDOSessionobject can contact its web application to see if it is allowed access. If a login session was never previously authenticated, theJSDOSessionnever even tries to contact its web application. This communication also depends on theauthenticationModelsetting passed to the object’s constructor. - info
- A JavaScript object that can have the following properties:
xhr— A reference to the XMLHttpRequest object, if any, sent to the web server to make the authorization request to the web application. If no request was made, this property is undefined.offlineReason— Astringconstant that is set only ifisAuthorized( )determines that theJSDOsessionobject is disconnected from its web application or its associated application server. The returned value indicates the reason for theJSDOsessionoffline state. Possible values include some of those returned by a call to theping( )method, as follows:progress.data.Session.DEVICE_OFFLINE— The device itself is offline. For example, it might be in airplane mode, or it might be unable to pick up a Wi-Fi or cell signal.progress.data.Session.SERVER_OFFLINE— The web server is not available. For a Rollbase Data Object Service, this is the web server for the public or private cloud. For an OpenEdge Data Object Service, this is the Tomcat Java servlet container.progress.data.Session.WEB_APPLICATION_OFFLINE— The server is running, but the Java web application that implements the Data Object Service is not deployed.
Additional information
The behavior of isAuthorized( ) in a web
app after a browser page refresh depends on whether page refresh support is enabled by
passing an operative value for the name property in the
JSDOSession object constructor.
For example, if page refresh support has not been
enabled, regardless of the authentication model, after the user initiates a page refresh,
but before a new login session has been established by calling the
login( ) method, the callback result parameter is always set to progress.data.Session.LOGIN_AUTHENTICATION_REQUIRED. For more information on
page refresh support, see the description of the progress.data.JSDOSession class constructor.
JSDOSession authentication
model is HTTP Basic, page refresh support is never enabled.Example
The following code fragment shows how you can use isAuthorized( ) to check the online state of a given JSDOSession object with page refresh support enabled in the JSDOSession constructor:
|
This web app example initially verifies if the instance variable (ablSession) for a JSDOSession
already references an instance and creates the instance if it does not already exist, with
HTTP Form authentication and page refresh enabled.
It then immediately calls isAuthorized( ) to determine if an existing login session is already established
from a restored prior session state. If it is established and authorized to access its web
application, the done( ) callback executes calling startApp(), which is a method that continues web app execution
using the restored JSDO login session. If it is not established or authorized (likely for a
first-time execution or prior logout), the fail( )
callback executes.
If the fail( ) callback executes either
because initial authentication for the JSDOSession has not
been done or authorization for a restored JSDOSession
failed, it calls showLogin(), which is a method that
prompts the user for credentials to call the login( )
method on the JSDOSession and then perhaps call startApp() (or the equivalent) if the new session login
succeeds.
If the fail( ) callback executes for
some other reason, it displays any available offline status (info.offlineReason) that might be the cause of the failure. Although not shown,
it can also inspect the returned XMLHttpRequest object (info.xhr) for more information on the failure.
See also:
name property (JSDOSession class), login( ) method (JSDOSession class), offline event, online event