Как правильно интегрировать MSAL с React-Admin.
Я использовал код, предоставленный Microsoft, и поместил его в Конструктор в приложении. js и он отлично работает с использованием метода перенаправления, за исключением того, что Я продолжаю получать экран входа в React-Admin по умолчанию за долю секунды, прежде чем он перенаправляется на страницу аутентификации MS.
Если я помещаю код MSAL на свою пользовательскую страницу входа (пустая страница), он переходит в al oop и аутентификация не работает.
Как мне избавиться от экрана входа в React-Admin?
import { UserAgentApplication } from 'msal';
class App extends Component {
constructor(props) {
super(props);
this.userAgentApplication = new UserAgentApplication({
auth: {
clientId: config.appId,
authority: config.authEndPoint,
},
cache: {
cacheLocation: "localStorage",
storeAuthStateInCookie: true
}
});
this.userAgentApplication.handleRedirectCallback(this.authCallback.bind(this));
var user = this.userAgentApplication.getAccount();
if (user != null) {
localStorage.setItem('token', user.idToken);
localStorage.setItem('userName', user.userName);
const userName = user.userName.toString();
fetch('http://localhost:5000/getuserid', {
mode: 'cors',
method: "GET",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'USERNAME': userName
},
}).then(res => res.json())
.then(res => {
if (res.id != null) {
localStorage.setItem('userID', res.id);
} else {
console.log('Failed to retreived id');
}
}).catch(
err => console.log(err))
}
this.state = {
isAuthenticated: (user !== null),
user: {},
error: null
};
if (user) {
// Enhance user object with data from Graph
//this.getUserProfile();
}
else {
const loginRequest = {
scopes: ["https://graph.microsoft.com/User.Read"]
}
this.userAgentApplication.loginRedirect(loginRequest);
}
}
authCallback(error, response) {
//handle redirect response
this.setState({
authenticated: true
});
}
render() {
return (
<Admin title="MyApp" >
...
</Admin>
);
}
}
export default App;