2017-12-16 30 views
0

私はauth0を使用しています。私はログインし、ログインページに戻ります。 URLで、私はこのauth0エラー - ログイン後、ログインページにリダイレクトされます

http://localhost:3000/login#access_token=TecYZ7snyHV-eIHScHWNFm885bR9akp2&expires_in=7200&token_type=Bearer&state=af6AJGNuu726MuTgk6iGUdFBfM4tmtBX&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJEUTNPVFl6UmpCRE9UQkVSVEZCTWpFek16ZzFOemMxTWtJMVFqazJRelJDTmpFd01UZ3dNdyJ9.eyJpc3MiOiJodHRwczovL2FwcDExNjMuYXV0aDAuY29tLyIsInN1YiI6ImF1dGgwfDVhMzQwYjk0MTk3YzRmNjhmMDA4M2UzYSIsImF1ZCI6IjBaeGhtREtyb2p5YTFqODVrUHNRRWRVZ1hVdm1LZFlyIiwiaWF0IjoxNTEzNDQzOTQ5LCJleHAiOjE1MTYwNzM2OTUsImF0X2hhc2giOiJiU1gxa3Z5ZzJSVEYxVXFLdTV0bDhnIiwibm9uY2UiOiJzWEtoWklxVWxTYUdVMjJfSjJLOF9Hckw4VDQzQWpySCJ9.pfgRCrPuBxMMO6obMkBL_VsCANPFU4LSKYzqXXw_TPKNAYu-qSIQUVnHPtoPMS7NpndgLxWeSvZdQgUMW1oTaDtDLYsbftc8KV-IpFkc269yHcpyMO3TzEczAHLcKT6Y3FpXN5tnnrHxF0wjBSIPh4JNVMkG8AJG4nq3m-uPUuEOQRNvaQGFnFTSJet-H5A5_9aFXVmrH1FmK2LYGGLCJucwOfrC6cV-RqbJRaJ2ZCcqOm3vK08J2bUOBop8Jh7LUoCxoBB480RBmMfqctsVQW9etT2nWft7jCei6ZEo-eE2fGiRbPusq2dVvDMB78ar3KIhplEccGNrbom1fmcMww 

ここだから私のコード

import history from '../history'; 
import auth0 from 'auth0-js'; 


export default class Auth { 
    auth0 = new auth0.WebAuth({ 
    domain: 'app1163.auth0.com', 
    clientID: '0ZxhmDKrojya1j85kPsQEdUgXUvmKdYr', 
    redirectUri: 'http://localhost:3000/login', 

    responseType: 'token id_token', 
    scope: 'openid' 
    }); 

    constructor() { 
    this.login = this.login.bind(this); 
    this.logout = this.logout.bind(this); 
    this.handleAuthentication = this.handleAuthentication.bind(this); 
    this.isAuthenticated = this.isAuthenticated.bind(this); 
    } 

    login() { 
    this.auth0.authorize(); 
    } 

    handleAuthentication() { 
    this.auth0.parseHash((err, authResult) => { 
     if (authResult && authResult.accessToken && authResult.idToken) { 
     this.setSession(authResult); 
     history.replace('/home'); 
     } else if (err) { 
     history.replace('/home'); 
     console.log(err); 
     alert(`Error: ${err.error}. Check the console for further details.`); 
     } 
    }); 
    } 

    setSession(authResult) { 
    // Set the time that the access token will expire at 
    let expiresAt = JSON.stringify((authResult.expiresIn * 1000) + new Date().getTime()); 
    localStorage.setItem('access_token', authResult.accessToken); 
    localStorage.setItem('id_token', authResult.idToken); 
    localStorage.setItem('expires_at', expiresAt); 
    // navigate to the home route 
    history.replace('/home'); 
    } 

    logout() { 
    // Clear access token and ID token from local storage 
    localStorage.removeItem('access_token'); 
    localStorage.removeItem('id_token'); 
    localStorage.removeItem('expires_at'); 
    // navigate to the home route 
    history.replace('/home'); 
    } 

    isAuthenticated() { 
    // Check whether the current time is past the 
    // access token's expiry time 
    let expiresAt = JSON.parse(localStorage.getItem('expires_at')); 
    return new Date().getTime() < expiresAt; 
    } 
} 

だ、誰かが私を伝えることができ、いただきました!間違って私のコードでは、なぜそのページにログインするために戻ってリダイレクトを参照してください?

私もログインできたかどうかを知りたいですか?私がURLをチェックすると、私は正常にログインしたように見えます。

答えて

1

redirectUri = localhost:3000/homeにする必要はありませんか?

+0

はい、ありがとうございます:) –

関連する問題