Skip to content
This repository has been archived by the owner on Oct 16, 2019. It is now read-only.

Commit

Permalink
sso cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkie committed Oct 13, 2016
1 parent ff21c83 commit 3244d3f
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 36 deletions.
21 changes: 21 additions & 0 deletions 11-Single-Sign-On/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Auth0, Inc. <[email protected]> (http://auth0.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
31 changes: 13 additions & 18 deletions 11-Single-Sign-On/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ You can read a more about client-side SSO in the Single Page Applications [here]

To run this quickstart you can fork and clone this repo.

Be sure to set the correct values for your Auth0 applications in both `auth0.variables.js` files.
Be sure to set the correct Auth0 credentials for your applications in the `auth0-variables.js` files of both applications in this sample.

Go to your [Clients](https://manage.auth0.com/#/clients), open your App, switch the `Use Auth0 instead of the IdP to do Single Sign On` flag on and save changes.
If you use two Auth0 applications for this example, then enable `Use Auth0 instead of the IdP to do Single Sign On` flag for both of them.

If you use two Auth0 applications for this example, enable `Use Auth0 instead of the IdP to do Single Sign On` flag for both of them.

You will also need to whitelist the URLs you want to redirect to when you log out of Auth0 SSO. These can be set in the [advanced settings](https://manage.auth0.com/#/account/advanced).

To run applications

Expand Down Expand Up @@ -47,10 +50,8 @@ Click `Logout from your Auth0 application` button on the example's `Home` page t
```html
<!-- index.html -->
<body>
...
<!-- Auth0's Lock-Passwordless library -->
<!--auth0.js library -->
<script type="text/javascript" src="bower_components/angular-auth0/dist/angular-auth0.js"></script>
...
</body>
```

Expand All @@ -61,15 +62,11 @@ Click `Logout from your Auth0 application` button on the example's `Home` page t

(function () {

...

function run($rootScope, authService, lock, $timeout) {

...

$timeout(authService.checkAuthOnRefresh);

...

}

Expand All @@ -83,8 +80,6 @@ Click `Logout from your Auth0 application` button on the example's `Home` page t

(function () {

...

function authService($rootScope, lock, angularAuth0, authManager, jwtHelper, $q) {

...
Expand All @@ -110,8 +105,6 @@ Click `Logout from your Auth0 application` button on the example's `Home` page t
}

return {

...

checkAuthOnRefresh: checkAuthOnRefresh,

Expand All @@ -138,26 +131,28 @@ Click `Logout from your Auth0 application` button on the example's `Home` page t
</div>
<div class="text-center">
<h2><a href="http://localhost:3001">Open the application #2</a></h2>
<button class="btn btn-danger" ng-click="vm.logoutFromAuth0()">Logout from your Auth0 application</button>
<button class="btn btn-danger" ng-click="vm.logoutFromAuth0()">Logout from your Auth0 applications</button>
</div>
</div>
```

### 5. Update `HomeController`
### 5. Add SSO Logout

The **Logout** link in the navbar logs the user out from the individual app, but to log the user out of SSO, you must call `auth0Angular.logout`.

> **Note:** You must set the URL that is allowed to be redirected to after logout in your [Auth0 advanced settings](https://manage.auth0.com/#/account/advanced).
```js
// components/home/home.controller.js

(function () {

...

function HomeController(authService) {

...

vm.logoutFromAuth0 = function() {
var auth0LogoutWindow = window.open('https://'+AUTH0_DOMAIN+'/logout', '_blank');
angularAuth0.logout({returnTo: 'http://localhost:3001/'});
}

}
Expand Down
5 changes: 0 additions & 5 deletions 11-Single-Sign-On/app1.com/components/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@
});
}

var ttt = false;
lock.on('test', function () {
console.log('test');
ttt = true;
});
function getProfileDeferred() {
return deferredProfile.promise;
}
Expand Down
7 changes: 4 additions & 3 deletions 11-Single-Sign-On/app1.com/components/home/home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
.module('app')
.controller('HomeController', HomeController);

HomeController.$inject = ['authService'];
HomeController.$inject = ['authService', 'angularAuth0'];

function HomeController(authService) {
function HomeController(authService, angularAuth0) {

var vm = this;
vm.authService = authService;
Expand All @@ -18,7 +18,8 @@
});

vm.logoutFromAuth0 = function() {
var auth0LogoutWindow = window.open('https://'+AUTH0_DOMAIN+'/logout', '_blank');
angularAuth0.logout({returnTo: 'http://localhost:3000/'});
authService.logout();
}

}
Expand Down
3 changes: 2 additions & 1 deletion 11-Single-Sign-On/app2.com/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
// Initialization for the angular-auth0 library
angularAuth0Provider.init({
clientID: AUTH0_CLIENT_ID,
domain: AUTH0_DOMAIN
domain: AUTH0_DOMAIN,
callbackURL: 'http://localhost:3001'
});

$urlRouterProvider.otherwise('/home');
Expand Down
7 changes: 1 addition & 6 deletions 11-Single-Sign-On/app2.com/components/auth/auth.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,7 @@

});
}

var ttt = false;
lock.on('test', function () {
console.log('test');
ttt = true;
});

function getProfileDeferred() {
return deferredProfile.promise;
}
Expand Down
7 changes: 4 additions & 3 deletions 11-Single-Sign-On/app2.com/components/home/home.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
.module('app')
.controller('HomeController', HomeController);

HomeController.$inject = ['authService'];
HomeController.$inject = ['$window', 'authService', 'angularAuth0'];

function HomeController(authService) {
function HomeController($window, authService, angularAuth0) {

var vm = this;
vm.authService = authService;
Expand All @@ -18,7 +18,8 @@
});

vm.logoutFromAuth0 = function() {
var auth0LogoutWindow = window.open('https://'+AUTH0_DOMAIN+'/logout', '_blank');
angularAuth0.logout({returnTo: 'http://localhost:3001/'});
authService.logout();
}

}
Expand Down

0 comments on commit 3244d3f

Please sign in to comment.