Как получить адрес электронной почты, введенный пользователем при входе в мое приложение vue js? - PullRequest
0 голосов
/ 30 октября 2018

Я использовал adal.js, чтобы разрешить вход в мое приложение vue js через активный каталог Azure. Однако я хочу ограничить приложение только несколькими пользователями в этом каталоге. Теперь я хочу знать адрес электронной почты, введенный пользователем сразу после того, как он нажал клавишу ввода, чтобы я мог затем проверить, должен ли я разрешить ему доступ или нет - т.е. перевести его на домашнюю страницу, если да, и запретить доступ, если нет.

Я пробовал следующее, но не могу получить auth._user. Показывает ноль.

import * as AuthenticationContext from 'adal-angular/lib/adal';

const config = {
    tenant: 'xxxxxxxxxxxx',
    clientId: 'xxxxxxxxxxxxxxxxxxxx',
    redirectUri: 'http://localhost:1337',
    cacheLocation: 'sessionStorage'
};

export default {
    authenticationContext: null,

    initialize() {

        this.authenticationContext = new AuthenticationContext(config);
        var auth = this.authenticationContext;

        return new Promise((resolve, reject) => {

            if (auth.isCallback(window.location.hash) || window.self !== window.top) {
                // redirect to the location specified in the url params.
                auth.handleWindowCallback();
            } else {

                // try pull the user out of local storage
                let user = auth.getCachedUser();

                if (user) {
                    resolve();
                } else {
                    // no user at all - go sign in.
                    this.signIn();
                }
            }
        });


    },
    /**
   * @return {Promise.<String>} A promise that resolves to an ADAL token for resource access
   */
    acquireToken() {
        return new Promise((resolve, reject) => {
            this.authenticationContext.acquireToken('https://Atkins.onmicrosoft.com/624c09d9-0646-4699-83b3-d8abdf1f5c47', (error, token) => {
                if (error || !token) {
                    return reject(error);
                } else {
                    return resolve(token);
                }
            });
        });
    },
    /**
     * Issue an interactive authentication request for the current user and the api resource.
     */
    acquireTokenRedirect() {
        this.authenticationContext.acquireTokenRedirect('https://Atkins.onmicrosoft.com/624c09d9-0646-4699-83b3-d8abdf1f5c47');
    },
    /**
     * @return {Boolean} Indicates if there is a valid, non-expired access token present in localStorage.
     */
    isAuthenticated() {
        // getCachedToken will only return a valid, non-expired token.
        if (this.authenticationContext.getCachedToken(config.clientId)) { return true; }
        return false;
    },
    /**
   * @return {Object} An ADAL user profile object.
   */
    getUserProfile() {
        return this.authenticationContext.getCachedUser().profile;
    },
    signIn() {
        this.authenticationContext.login();
    },
    signOut() {
        this.authenticationContext.logOut();
    }

};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...