AngularJS-OAuth2 icon indicating copy to clipboard operation
AngularJS-OAuth2 copied to clipboard

Use with ui-router

Open simo3o opened this issue 9 years ago • 2 comments

Is it possible to use the requireToken: true with ui-router?

simo3o avatar Jul 27 '16 11:07 simo3o

I would like to know this too, can you use this with ui-router at all?

SteveDowsett avatar Jan 23 '17 18:01 SteveDowsett

Hi guys. I made a lot of changes for this to work with the latest version of IdentityServer4. I also created a Sign Up button option for my personal use.

I changed this part of code in order to use it with ui-router:

// Open ID Sign In directive
    angular.module('oauth2.directive', [])
		.config(['$stateProvider', function ($stateProvider) {
		    $stateProvider
            .state('silent-renew', {
                name: 'SilentRenew',
                url: '/silent-renew',
                template: ''
            })
		}])

On function init() I changed:

$rootScope.$on('$stateChangeStart', stateChangeHandler);

and the "routeChangeHandler" function I changed for:

function stateChangeHandler(event, toState, toParams, fromState, fromParams, options) {
		            if (toState && toState.requireToken) {
		                if (!accessToken.get() || expired(accessToken.get())) {
		                    event.preventDefault();
		                    $window.sessionStorage.setItem('oauthRedirectRoute', toState.url);

		                    if (scope.signUpMode) {
		                        endpoint.signUp();
		                    } else {
		                        endpoint.authorize();
		                    }
		                }
		            }
		        };

Good luck. Let me know if it works for you.

dtkern avatar Feb 10 '17 14:02 dtkern