TokenStoreManager
stormpath.tokenStore
This service provides methods for registering token stores (with duck-typed validation), as well as retrieving them by name.
Token store implementations must implement the TokenStore interface.
All token stores are expected to satisfy the following contract:
put method that takes a key and a value, stores them, and returns a promise indicating successget method that takes a key and returns a promise containing the value for the given key, or a rejection with a reasonremove method that takes a key and removes the value, returning the result as a promiseSee LocalStorageTokenStore for an example of an implementation.
| Param | Type | Details |
|---|---|---|
| name | String | The name of the token store implementation. |
| TokenStore | The token store implementation stored under that name |
| Param | Type | Details |
|---|---|---|
| name | String | The name under which to store the token store implementation |
| tokenStore | TokenStore | A concrete TokenStore |
angular.module('app')
.run(['$q', 'TokenStoreManager', function($q, TokenStoreManager) {
// Can also be provided by a service/factory for better code organisation
var myStore = {
data: {},
get: function get(key) {
return this.data[key] ? $q.resolve(this.data[key]) : $q.reject();
},
put: function put(key, value) {
this.data[key] = value;
return $q.resolve();
},
remove: function remove(key) {
delete this.data[key];
return $q.resolve();
}
};
TokenStoreManager.registerTokenStore('basicStore', myStore);
var alsoMyStore = TokenStoreManager.getTokenStore('basicStore');
}]);