简体   繁体   English

如何修复 Google OAuth 401 错误无效客户端?

[英]How can I fix the Google OAuth 401 Error invalid client?

I am working with OAuth Google API and I am getting the 401 Error: invalid_client .我正在使用 OAuth Google API 并且收到401 Error: invalid_client It is nothing to do with clientID or clientSecret code, because I'm sure that I copied the keys perfectly.这与clientIDclientSecret代码无关,因为我确信我完美地复制了密钥。 I created again a new credential to make sure that it is not a problems of the Google API, but the error still exists.我再次创建了一个新凭据以确保它不是 Google API 的问题,但错误仍然存在。 I also don't receive any error in the console when I am running the server.当我运行服务器时,我也没有在控制台中收到任何错误。 Could someone helps me, please?有人可以帮助我吗?

It is what I receive from the browser:这是我从浏览器收到的:

 > 401. That's an error. > > Error: invalid_client > > The OAuth client was not found. > > Request Details > response_type=code > redirect_uri=http://localhost:5000/auth/google/callback > scope=profile email > client_id=keys.googleClientID > That's all we know.

This is part of my code:这是我的代码的一部分:

 passport.use(
      new GoogleStrategy(
        {
          clientID: 'keys.googleClientID',
          clienSecret: 'keys.googleClientSecret',
          callbackURL: '/auth/google/callback'
        },
        (accessToken, refreshToken, profile, done) => {
          console.log('access token', accessToken);
          console.log('refresh token', refreshToken);
          console.log('profile', profile);
        }
      )
    );

  app.get(
    '/auth/google',
    passport.authenticate('google',{
      scope: ['profile', 'email']
    })
  );
  app.get('/auth/google/callback', passport.authenticate('google'));

Thanks: :)谢谢: :)

As i mentioned in my comment it looks to me that you are sending 'keys.googleClientID' which is not a valid key you need to send the value of the variable.正如我在评论中提到的那样,在我看来,您正在发送“keys.googleClientID”,这不是您需要发送变量值的有效密钥。 keys.googleClientID keys.googleClientID

 passport.use(
      new GoogleStrategy(
        {
          clientID: keys.googleClientID,
          clientSecret: keys.googleClientSecret,
          callbackURL: '/auth/google/callback'
        },
        (accessToken, refreshToken, profile, done) => {
          console.log('access token', accessToken);
          console.log('refresh token', refreshToken);
          console.log('profile', profile);
        }
      )
    );

you should make sure to have Google+ API enabled and this Similar Fixes could help you whose information ranges from either acquiring new keys to setting The product name which can be set in the Consent screen section of the Google Developers Console for your project.您应该确保启用了 Google+ API,并且此类似修复可以帮助您,其信息范围从获取新密钥到设置可以在 Google Developers Console 的同意屏幕部分为您的项目设置的产品名称。 Look under APIs & auth in the left navigation and select Consent screen.在左侧导航和 select 同意屏幕中查看 APIs & auth。 You need also to set your email address in the box above the product name.您还需要在产品名称上方的框中设置您的 email 地址。 Setting EMAIL ADDRESS and PRODUCT NAME in the consent screen of Google developer console, also solves the error在 Google 开发者控制台的同意屏幕中设置 EMAIL ADDRESS 和 PRODUCT NAME,也解决了错误

and if you are using the config module that is const config = require("config"); const keys = config.get('keys');如果您使用的是配置模块const config = require("config"); const keys = config.get('keys'); const config = require("config"); const keys = config.get('keys'); could you try this by using a template string你能用模板字符串试试这个吗

passport.use( new GoogleStrategy( { clientID: ${keys.googleClientID}`,use backticks before $ and after closing } passport.use( new GoogleStrategy( { clientID: ${keys.googleClientID}`,在$之前和之后使用反引号}

      clientSecret: `${keys.googleClientSecret}`, //do like this for the above clientID 
      callbackURL: '/auth/google/callback'
    },
    (accessToken, refreshToken, profile, done) => {
      console.log('access token', accessToken);
      console.log('refresh token', refreshToken);
      console.log('profile', profile);
    }
  )
);

that is backtick ${keys.googleClientID} backtick im saying backtick because stackoverflow would format the backtick (``)那是反引号 ${keys.googleClientID} 反引号我说反引号,因为stackoverflow会格式化反引号(``)

or by using the actual variable passport.use( new GoogleStrategy( { clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken, refreshToken, profile, done) => { console.log('access token', accessToken); console.log('refresh token', refreshToken); console.log('profile', profile); } ) );或使用实际变量passport.use( new GoogleStrategy( { clientID: keys.googleClientID, clientSecret: keys.googleClientSecret, callbackURL: '/auth/google/callback' }, (accessToken, refreshToken, profile, done) => { console.log('access token', accessToken); console.log('refresh token', refreshToken); console.log('profile', profile); } ) ); plus you had also misspelled clientSecret in your code it is clienSecret另外,您在代码中还拼错了 clientSecret 它是 clienSecret

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google oauth2.0显示无效的客户端错误 - Google oauth2.0 showing Invalid client error 如何修复api-3和OAuth-2.0中更新博客的401未授权错误 - how to fix 401 unauthorized error for update blogger usin api-3 and OAuth-2.0 使用 OMDB API 时如何修复 401 错误? - How do I fix 401 error when using OMDB API? 我被困在“ 401。 这是一个错误错误:invalid_client” - I am stuck with a “401. That's an error Error: invalid_client” OAuth2.0 令牌发布请求响应 401 (invalid_client) - OAuth2.0 token post request is responding 401 (invalid_client) 如何修复 Node js 中的错误 Invalid Sec-WebSocket-Accept 标头? - How can I fix the Error Invalid Sec-WebSocket-Accept header in Node js? Microsoft Oauth2(令牌端点)-无效的客户端错误 - Microsoft Oauth2 (token endpoint) - invalid client error 我的代码返回此错误“错误:未知:赋值表达式中的左侧无效 (31:1)”。 我该如何解决? - My code returns this error "error: unknown: Invalid left-hand side in assignment expression (31:1)". How can I fix it? 如何解码 google OAuth 2.0 JWT / 凭据令牌? - How can I decode a google OAuth 2.0 JWT / credential token? 如何访问谷歌 Oauth2 护照中的个人资料信息? - How can I access profile information in google Oauth2 passport?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM