我正在开发一个react原生应用程序,我在使用OpenID connect时遇到了一些问题。我想使用一些“登录与谷歌”的功能。
在普通的(非原生的) react应用中,我使用react-google-login库,如下所示:
import { GoogleLogin} from 'react-google-login';
import axios from 'axios';
const CLIENT_ID = 'xxxxx.apps.googleusercontent.com';
const Login = () => {
const loginHandler = (response) => {
// I can use the OpenID JWT token got as response.tokenId e.g.
axios.get("/myapi", {
headers: {
Authorization: 'Bearer ' + response.tokenId
}
}).then(res => {
...
});
}
return (
<React.Fragment>
<GoogleLogin
clientId={CLIENT_ID}
buttonText='Login'
onSuccess={loginHandler}
cookiePolicy={'single_host_origin'}
responseType='code,token'
uxMode="redirect"
/>
</React.Fragment>
)
}
export default Login;如您所见,在登录处理程序中,我可以使用OpenID JWT令牌并将其发送到服务器。
我需要在React Native中使用同样的库,但我还没有找到任何简单的库。它们都只返回Oauth2访问令牌,而不返回OpenID JWT令牌。
有没有人知道我应该使用哪个库以及如何使用?
谢谢
发布于 2021-03-02 18:45:11
也许你应该使用这个库
npm install react-native-app-auth --savereact-native link react-native-app-auth如果您使用yarn作为包管理器
yarn add @react-native-app-auth发布于 2021-03-03 03:12:26
最后,我设法用AppAuth实现了这一点
https://stackoverflow.com/questions/66437688
复制相似问题