【问题标题】:React Native with Google OpenID Connect使用 Google OpenID Connect 反应原生
【发布时间】:2021-05-31 21:30:17
【问题描述】:

我正在开发一个 React Native 应用程序,但我在使用 OpenID 连接时遇到了一些问题。我想使用一些“使用 Google 登录”功能。

在普通(非原生)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 中也需要同样的东西,但我还没有找到任何简单的库。它们都没有返回 OpenID JWT 令牌,只返回 Oauth2 访问令牌。

有人知道我应该使用哪个库以及如何使用吗?

谢谢

【问题讨论】:

    标签: react-native authentication jwt google-oauth openid-connect


    【解决方案1】:

    也许你应该使用这个库

    npm install react-native-app-auth --savereact-native link react-native-app-auth
    

    如果你使用 yarn 作为包管理器

    yarn add @react-native-app-auth
    

    【讨论】:

    【解决方案2】:

    最后我设法用AppAuth完成了这个

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-26
      • 2018-09-19
      • 2015-02-09
      • 2021-01-04
      • 1970-01-01
      • 1970-01-01
      • 2019-07-16
      • 1970-01-01
      相关资源
      最近更新 更多