JamesRandall / AngularJS-OAuth2

Package for allowing an AngularJS application to authenticate with an OAuth 2 / Open ID Connect identity provider using the implicit flow.
MIT License
46 stars 42 forks source link

location hash issue running angularjs 1.6.1 and html5mode false #48

Open rowdyy1960 opened 7 years ago

rowdyy1960 commented 7 years ago

Looks like there is an issue with angularjs 1.6.1 if you are running with $locationProvider.html5Mode(false) where it is now adding a #! to the beginning of the hash. the issue is detailed here. https://docs.angularjs.org/guide/migration#commit-aa077e8

this causes the id_token to be lost in getTokenFromHasParams. Its not difficult to fix, either set html5Mode to true, or add $locationProvider.hasPrefix('') to app.module configuration:

(function () {

var app = angular.module('MainModule',["ngRoute","afOAuth2"]);

//configure routing. Add restircted: true to require authentication

app.config(function ($routeProvider, $locationProvider) {
    $locationProvider.html5Mode(false);
    $locationProvider.hashPrefix('');

    $routeProvider
        .when('/',{
            templateUrl: 'index.html',
            controller: 'MainController'
            ,requireToken: true
        }).otherwise({
            redirectTo: "/"
        });
});

}());