Component to integrate with an Authomator backend:
- includes
auth
service with authentication logic - includes
session
service to keep track of session data - exposes
auth
andsession
on$rootScope
- includes code to check access during application bootstrap
- includes code to check access during route/state changes
- includes HTTP interceptor that redirects to login page when 401 response is received
- includes unit tests
First install the component:
$ ngx install angular-authomator
Then:
- edit
app.config.authomator.js
in the_build
directory and supply your Authomator url. - remove files you don't need e.g. if you don't need a state change listener, HTTP interceptor, etc.
No clue what the ngx
command line tool is? Learn more about AngularJS Express.
Make sure the angular-authomator module is loaded.
Redirect to the Authomator login page. Helper function for auth.login() but can be called directly as well.
none
void
In script:
if(!auth.isLoggedIn()){
return auth.redirectToLoginPage();
}
In markup:
<a ng-click="auth.redirectToLoginPage()">Log in</a>
Log in. Redirect to Authomator login page.
After logging in successfully on the Authomator login page, the session
data will be available and auth.isLoggedIn()
will return true
.
none
void
In script:
if(!auth.isLoggedIn()){
return auth.logIn();
}
In markup:
<a ng-click="auth.logIn()">Log in</a>
Log out. Log out user and destroy session data.
none
void
In script:
if(auth.isLoggedIn()){
return auth.logOut();
}
In markup:
<a ng-click="auth.logOut()">Log out</a>
Checks whether user is logged in or not.
none
Boolean
In script:
if(!auth.isLoggedIn()){
return auth.redirectToLoginPage();
}
In markup:
<h1 ng-if="auth.isLoggedIn()">Logged in!</h1>
Get identity.
none
Object
: the entire identity as it was returned by Authomator, already decoded from the identity token.
In script:
var identity = session.getIdentity();
In markup:
<pre ng-if="auth.isLoggedIn()">
{{ session.getIdentity() | json }}
</pre>
Get identity token.
none
String
: the identity token as it was provided by Authomator
In script:
var token = session.getIdentityToken();
In markup:
<pre ng-if="auth.isLoggedIn()">
{{ session.getIdentityToken() | json }}
</pre>
Get access token.
none
String
: the access token as it was provided by Authomator
In script:
var token = session.getAccessToken();
In markup:
<pre ng-if="auth.isLoggedIn()">
{{ session.getAccessToken() | json }}
</pre>
Get refresh token.
none
String
: the refresh token as it was provided by Authomator
In script:
var token = session.getRefreshToken();
In markup:
<pre ng-if="auth.isLoggedIn()">
{{ session.getRefreshToken() | json }}
</pre>
Remove all session data. Clears the identity and all tokens.
There usually is no need to call this method directly. Use auth.logOut()
, which will call this method for you.
none
String
: the refresh token as it was provided by Authomator
In script:
session.destroy();
In markup:
<a ng-click="session.destroy()">Destroy the session</a>
- Used in production
- Added HTTP interceptor
- Added access control scripts
- Added session service
- Added auth service
- Initial version
MIT.