在React-Native
应用程序中,我使用react-native-azure-ad@0.2.4“实现了Microsoft的AD登录功能。
从Microsoft的帐户注销时遇到问题。当我触发Logout时,首先LoginView.js被渲染,然后ADLoginView(WebView)重定向到Microsofts登录页面,在输入新的用户ID时,应用程序将我带回旧的登出用户登录。 [基本上以前的用户令牌已存储,我无法清除]
请参阅下面的ScreenShot
/ ** Login.js **/
let needLogout
export default class Login extends Component {
constructor(){
super()
this.state = {
logout : false
}
new ReactNativeAD({
client_id: CLIENT_ID,
authority_host: 'https://login.windows.net/common',
redirect_uri: 'http://xxz.myappdomain.biz',
resources: [
'https://graph.microsoft.com',
]
})
context = ReactNativeAD.getContext(CLIENT_ID)
}
componentDidMount(){
needLogout = () => this.needLogoutSetFalse()
EventBus.addEventListener("Logout", needLogout);
}
render(){
return(
<ADLoginView
context={context}
onSuccess={this.onLoginSuccess.bind(this)}
hideAfterLogin = {true}
needLogout = {this.state.logout}
/>)
}
onLoginSuccess(credentials){
//Call The graph API and Navigate to Next view
}
needLogoutSetFalse(){
EventBus.removeEventListener("Logout", needLogout)
ReactNativeAD.removeContext(CLIENT_ID)
// By Setting needLogout true Webview will redirect to n . Microsoft’s official login page.
this.setState({logout: true})
}
}
/** Logout.js **/
onClickLogOut(){
// Will Clear Entire Async Storage.
userInfo.removeUser().then(()=>{
// Will Navigate to Login Page
this.props.navigation.dispatch(resetAction)
// Invoke the needLogoutSetFalse method from Login.js.
EventBus.dispatch("Logout")
Toast.show('Log out successful')
})
}
答案 0 :(得分:1)