我想创建react native应用程序集成keycloack并获取令牌来访问Nodejs服务器api,我使用的包是react-native-app-auth,github:https://github.com/FormidableLabs/react-native-app-auth
但仍然无法正常工作,当我单击按钮应用程序退出并出现错误
时在这里编码
<!-- language: lang-js -->
import { authorize } from 'react-native-app-auth';
const config = {
issuer: 'http://localhost:8080/auth/realms/testrealms',
clientId: 'passport',
redirectUrl: 'io.identityserver.demo:/callback',
scopes: ['openid', 'profile']
};
export default class App extends Component<Props> {
constructor(props) {
super(props);
this.state = {
hasLoggedInOnce: false,
accessToken: '',
accessTokenExpirationDate: '',
refreshToken: ''
}
}
authorize = async () => {
try {
const authState = await authorize(config);
this.setState(
{
hasLoggedInOnce: true,
accessToken: authState.accessToken,
accessTokenExpirationDate: authState.accessTokenExpirationDate,
refreshToken: authState.refreshToken
},
500
);
} catch (error) {
Alert.alert('Failed to log in', error.message);
}
};
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
React Native Authorize By Keycloak
</Text>
<Text style={styles.instructions}>
{this.state.accessToken}
</Text>
<View>
{
!this.state.accessToken && (
<Button onPress={() => {
this.authorize()
}} title='authorize' />
)
}
</View>
</View>
);
}
}
<!-- end snippet -->