new Rest(moduleName, settings) → {Object}
Status: Stable
The REST adapter is the default type used when creating a new authentication module. It uses jQuery.ajax to communicate with the server.
This constructor is instantiated when the "Auth.add()" method is called
Parameters:
Name | Type | Argument | Default | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
moduleName |
String | the name used to reference this particular auth module | |||||||||||||||||
settings |
Object |
<optional> |
{} | the settings to be passed to the adapter
Properties
|
- Source:
Returns:
The created auth module
- Type
- Object
Example
// Create an empty Authenticator
var auth = AeroGear.Auth();
// Add a custom REST module to it
auth.add( {
name: "module1",
settings: {
baseURL: "http://customURL.com"
}
});
// Add a custom REST module to it with custom security endpoints
auth.add( {
name: "module2",
settings: {
endpoints: {
enroll: "register",
login: "go",
logout: "leave"
}
}
});
Methods
-
enroll(data, options) → {Object}
-
Enroll a new user in the authentication system
Parameters:
Name Type Argument Default Description data
Object User profile to enroll options
Object <optional>
{} Options to pass to the enroll method Properties
Name Type Argument Description baseURL
String <optional>
defines the base URL to use for an endpoint contentType
String <optional>
set the content type for the AJAX request dataType
String <optional>
specify the data expected to be returned by the server xhrFields
Object <optional>
specify extra xhr options, like the withCredentials flag complete
AeroGear~completeCallbackREST <optional>
a callback to be called when the result of the request to the server is complete, regardless of success error
AeroGear~errorCallbackREST <optional>
callback to be executed if the AJAX request results in an error success
AeroGear~successCallbackREST <optional>
callback to be executed if the AJAX request results in success - Source:
Returns:
The jqXHR created by jQuery.ajax- Type
- Object
Example
var auth = AeroGear.Auth( "userAuth" ).modules.userAuth, data = { userName: "user", password: "abc123", name: "John" }; // Enroll a new user auth.enroll( data ); // Add a custom REST module to it with custom security endpoints var custom = AeroGear.Auth({ name: "customModule", settings: { endpoints: { enroll: "register", login: "go", logout: "leave" } } }).modules.customModule, data = { userName: "user", password: "abc123", name: "John" }; custom.enroll( data, { baseURL: "http://customurl/", success: function( data ) { ... }, error: function( error ) { ... } });
-
login(data, options) → {Object}
-
Authenticate a user
Parameters:
Name Type Argument Default Description data
Object A set of key/value pairs representing the user's credentials options
Object <optional>
{} An object containing key/value pairs representing options Properties
Name Type Argument Description baseURL
String <optional>
defines the base URL to use for an endpoint contentType
String <optional>
set the content type for the AJAX request dataType
String <optional>
specify the data expected to be returned by the server complete
AeroGear~completeCallbackREST <optional>
a callback to be called when the result of the request to the server is complete, regardless of success error
AeroGear~errorCallbackREST <optional>
callback to be executed if the AJAX request results in an error success
AeroGear~successCallbackREST <optional>
callback to be executed if the AJAX request results in success - Source:
Returns:
The jqXHR created by jQuery.ajax- Type
- Object
Example
var auth = AeroGear.Auth( "userAuth" ).modules.userAuth, data = { userName: "user", password: "abc123" }; // Enroll a new user auth.login( data ); // Add a custom REST module to it with custom security endpoints var custom = AeroGear.Auth({ name: "customModule", settings: { endpoints: { enroll: "register", login: "go", logout: "leave" } } }).modules.customModule, data = { userName: "user", password: "abc123", name: "John" }; custom.login( data, { baseURL: "http://customurl/", success: function( data ) { ... }, error: function( error ) { ... } });
-
logout(options) → {Object}
-
End a user's authenticated session
Parameters:
Name Type Argument Default Description options
Object <optional>
{} An object containing key/value pairs representing options Properties
Name Type Argument Description baseURL
String <optional>
defines the base URL to use for an endpoint complete
AeroGear~completeCallbackREST <optional>
a callback to be called when the result of the request to the server is complete, regardless of success error
AeroGear~errorCallbackREST <optional>
callback to be executed if the AJAX request results in an error success
AeroGear~successCallbackREST <optional>
callback to be executed if the AJAX request results in success - Source:
Returns:
The jqXHR created by jQuery.ajax- Type
- Object
Example
var auth = AeroGear.Auth( "userAuth" ).modules.userAuth; // Enroll a new user auth.logout(); // Add a custom REST module to it with custom security endpoints var custom = AeroGear.Auth({ name: "customModule", settings: { endpoints: { enroll: "register", login: "go", logout: "leave" } } }).modules.customModule, data = { userName: "user", password: "abc123", name: "John" }; custom.logout({ baseURL: "http://customurl/", success: function( data ) { ... }, error: function( error ) { ... } });