OAuthAuthorization
Class used to authorize a mobile user against Oracle Mobile Cloud Enterprise. Callers should use
MobileBackend's authorization property.
Extends
Members
isAuthorized :Boolean
Returns true if a user has been authorized, false otherwise. A user can be authorized by calling authenticate() or authenticateAnonymous().
Type:
- Boolean
- Inherited From:
- Source:
Methods
authenticate(username, password) → {Promise.<NetworkResponse>}
Authenticates a user with the given credentials against the service.
The user remains logged in until logout() is called.
Parameters:
Name | Type | Description |
---|---|---|
username |
String | The username of the credentials. |
password |
String | The password of the credentials. |
Returns:
- Type
- Promise.<NetworkResponse>
authenticateAnonymous() → {Promise.<NetworkResponse>}
Authenticates an anonymous user against the service. The user remains logged in until logout() is called.
Returns:
- Type
- Promise.<NetworkResponse>
getAccessToken() → {String}
Returns the current access token from user credentials.
- Inherited From:
- Source:
Returns:
current access token from user credentials.
- Type
- String
getAuthorizedUserName() → {String}
Returns the username of the current authorized user if any, null otherwise.
- Overrides:
- Source:
Returns:
- Type
- String
getClientId() → {String}
Returns the client ID for the current backend.
Returns:
- Type
- String
getClientSecret() → {String}
Returns the client secret for the current backend.
Returns:
- Type
- String
getCurrentUser() → {Promise.<(MCSAuthorization~CurrentUserData|NetworkResponse)>}
Returns the user resource associated with the logged in user.
- Inherited From:
- Source:
Returns:
- Type
- Promise.<(MCSAuthorization~CurrentUserData|NetworkResponse)>
Examples
Example usage of mcs.mobileBackend.authorization.getCurrentUser()
mcs.mobileBackend.authorization.getCurrentUser().then(
function(data){
},
function(exception){
});
// Response example
{
"id": "c9a5fdc5-737d-4e93-b292-d258ba334149",
"username": "DwainDRob",
"email": "js_sdk@mcs.com",
"firstName": "Mobile",
"lastName": "User",
"properties": {}
}
getOAuthTokenUrl() → {String}
Constructs a full URL, including the prefix, for the OAuth token endpoint.
Returns:
The full URL for the OAuth token endpoint.
- Type
- String
logout()
Logs out the current user and clears credentials and tokens.
onAuthentication(callback)
Subscribe for on authentication event
Parameters:
Name | Type | Description |
---|---|---|
callback |
Authorization~OnAuthenticationCallback | The callback that will be called when authentication happen. |
- Inherited From:
- Source:
refreshToken() → {Promise.<NetworkResponse>}
For OAuth, the SDK can not refresh because it does not persist client credentials.
This function only exists here because it inherits from the Authorization object, which is also used for other types of authentication in which the token can expire.
Returns:
- Type
- Promise.<NetworkResponse>