oauth-2.0 错误:实现OAuth 2.0时idpiframe_initialization_failed

ggazkfy8  于 2022-10-31  发布在  其他
关注(0)|答案(2)|浏览(305)

我在Web应用程序中使用OAuth 2.0时遇到此错误。我正在React中构建应用程序。我还创建了OAuth客户端ID。我使用的是Google Chrome浏览器:

{error: 'idpiframe_initialization_failed', details: 'You have created a new client application that use…i/web/guides/gis-migration) for more information.'}

下面是我的Google Auth代码在基于React的网络应用程序:

import React from 'react';

class GoogleAuth extends React.Component {
    state = { isSignedIn: null };

     componentDidMount() {
         window.gapi.load('client:auth2', () => {
             window.gapi.client.init({
                 clientId: '716075642837-kergfh0638hu8iq5dimpgnlc1f08s61r.apps.googleusercontent.com',
                 scope: 'email'
             }).then(() => {
                 this.auth = window.gapi.auth2.getAuthInstance();
                 this.setState({isSignedIn: this.auth.isSignedIn.get()})
             });
         });
     }

     renderAuthButton() {
         if(this.state.isSignedIn === null) {
             return <div> I don't know if we are signed in </div>;
         } else if(this.state.isSignedIn) {
             return <div>I am signed in</div>
         } else {
             return <div>I am not signed in</div>
         }
     }

    render() {
        return <div> {this.renderAuthButton() } </div>;
    }
}

export default GoogleAuth;
wwwo4jvm

wwwo4jvm1#

您必须在作用域后添加plugin_name

window.gapi.load('client:auth2', () => {
             window.gapi.client.init({
                 clientId: '716075642837-kergfh0638hu8iq5dimpgnlc1f08s61r.apps.googleusercontent.com',
                 scope: 'email',
               **plugin_name: 'streamy'**
             }).then(() => {
                 this.auth = window.gapi.auth2.getAuthInstance();
                 this.setState({isSignedIn: this.auth.isSignedIn.get()})
             });
         });
     }```
eoigrqb6

eoigrqb62#

您正在使用的Google库将被弃用;相反,您可以使用新的Google Identity Services for Web
由于您在2022年7月29日之前生成了客户ID,因此您可以通过设置plugin_name : 'Any Descriptive Name'以及clientIdscope来使用旧版Google库:

window.gapi.client.init({
            clientId: '716075642837-kergfh0638hu8iq5dimpgnlc1f08s61r.apps.googleusercontent.com',
            scope: 'email',
            plugin_name: 'PLUGIN'
        })

相关问题