An Angular 1.x extension to salte-auth that automatically registers any secured routes for ng-route
and ui-router
.
You can install this package either with npm
or with bower
.
$ npm install @salte-io/salte-auth-angularjs
Then add a <script>
to your index.html:
<script src="/node_modules/@salte-io/salte-auth-angularjs/dist/salte-auth-angularjs.js"></script>
Or require('@salte-io/salte-auth-angularjs')
from your code.
$ bower install salte-io/salte-auth-angularjs
Then add a <script>
to your index.html:
<script src="/bower_components/salte-auth-angularjs/dist/salte-auth-angularjs.js"></script>
Setting up OAuth in Angular is as simple as providing a config!
See the documentation for salte-auth for a full list of the configuration options.
import SalteAuthAngular from '@salte-io/salte-auth-angularjs';
const module = angular.module('Example', [
SalteAuthAngular
]);
module.config((SalteAuthServiceProvider) => {
// It's possible to secure individual routes with the following libraries:
// NG Route
// $routeProvider.when('/', {
// template: 'Home',
// secured: true
// });
// UI Router
// $stateProvider.state('home', {
// url: '/',
// secured: true
// });
SalteAuthServiceProvider.setup({
providerUrl: 'https://salte-alpha.auth0.com',
responseType: 'id_token',
redirectUrl: location.origin,
clientId: 'mM6h2LHJikwdbkvdoiyE8kHhL7gcV8Wb',
scope: 'openid',
endpoints: [
'https://jsonplaceholder.typicode.com/posts/1'
],
provider: 'auth0'
});
}]);
module.run((SalteAuthService) => {
SalteAuthService.signInWithIframe().then(() => {
console.log('we did it!');
});
});
SalteAuthService
has all the same public properties and methods as salte-auth.