Не удается войти с блокировкой auth0
Я использую auth0 для создания функции входа в систему с angularjs.
При вводе адреса электронной почты и пароля вход в систему не возвращается, и я снова перенаправляю на страницу входа. Я проверяю данные возврата не вижу "id_token".
app.js включает конфигурацию аутентификации
var rootApp = angular.module('xxxx', [ 'auth0.lock', ]); rootApp.config(function(lockProvider) { lockProvider.init({ clientID: 'xxxxx', домен: 'xxxx', auth:{ redirectUrl: window.location.origin + '/callback', responseType: 'token', параметры: { scope: 'openid profile' } }, параметры: { _idTokenVerification: true, configurationBaseUrl: 'https://cdn.auth0.com', тема: {logo: '/ logos / full_size / medium.png', primaryColor: ' # C59D18 '}}});});
auth.service.js
(function () {
'use strict';
angular.module('BlurAdmin')
.service('authService', authService);
authService.$inject = ['lock', '$location'];
function authService(lock, $location) {
function login() {
// Display the Lock widget using the
// instance initialized in the app.js config
lock.show();
}
function logout() {
// Remove tokens and expiry time from localStorage
localStorage.removeItem('access_token');
localStorage.removeItem('id_token');
localStorage.removeItem('expires_at');
$location.path('/');
}
function handleAuthentication() {
// Uncomment if you are not using HTML5Mode
// lock.interceptHash();
lock.on('authenticated', function(authResult) {
if (authResult && authResult.accessToken && authResult.idToken) {
console.log('Authenticated!', authResult);
_setSession(authResult);
}
});
lock.on('authorization_error', function(err) {
console.log(err);
alert(
'Error: ' + err.error + '. Check the console for further details.'
);
});
}
function _setSession(authResult) {
// Set the time that the Access Token will expire
var expiresAt = JSON.stringify(
authResult.expiresIn * 1000 + new Date().getTime()
);
// Save tokens and expiration to localStorage
localStorage.setItem('access_token', authResult.accessToken);
localStorage.setItem('id_token', authResult.idToken);
localStorage.setItem('expires_at', expiresAt);
}
function isAuthenticated() {
// Check whether the current time is
// past the Access Token's expiry time
var expiresAt = JSON.parse(localStorage.getItem('expires_at'));
return new Date().getTime() < expiresAt;
}
return {
login: login,
logout: logout,
handleAuthentication: handleAuthentication,
isAuthenticated: isAuthenticated
};
}
})();
1 ответ
На первый взгляд вы, вероятно, не получаете id_token
потому что вы не указали в своем app.js
responseType
содержать id_token
:
auth: {
...
responseType: 'token id_token',
...
}
попробуйте, и вы должны быть хорошими, чтобы пойти!