[英]Feathers js - how to login by google
我正在按照文档创建谷歌策略。
当我通过浏览器访问 http://localhost:3030/oauth/google 时,出现以下错误:
Error Code 400: redirect_uri_mismatch
The redirect URI in the request, https://localhost/oauth/google/callback,
does not match the ones authorized for the OAuth client.
To update the authorized redirect URIs, visit: https://console.developers.google.com/apis/credentials/oauthclient/12345678-xxxx.apps.googleusercontent.com?project=xxxxyyyy
身份验证.js
const { AuthenticationService, AuthenticationBaseStrategy, JWTStrategy } = require('@feathersjs/authentication');
const { LocalStrategy } = require('@feathersjs/authentication-local');
const { expressOauth } = require('@feathersjs/authentication-oauth');
const axios = require('axios');
const { OAuthStrategy } = require('@feathersjs/authentication-oauth');
class GoogleStrategy extends OAuthStrategy {
async getEntityData(profile) {
const baseData = await super.getEntityData(profile);
// this will grab the picture and email address of the Google profile
return {
...baseData,
email: profile.email
};
}
}
module.exports = app => {
const authentication = new AuthenticationService(app);
authentication.register('jwt', new JWTStrategy());
authentication.register('local', new LocalStrategy());
authentication.register('google', new GoogleStrategy());
app.use('/authentication', authentication);
app.configure(expressOauth());
};
配置/本地.json
{
"authentication": {
"entity": "user",
"service": "users",
"secret": "SA3c59SscyH6TscABCdeFG=",
"authStrategies": [
"jwt",
"local",
"google"
],
"jwtOptions": {
"header": {
"typ": "access"
},
"audience": "https://yourdomain.com",
"issuer": "feathers",
"algorithm": "HS256",
"expiresIn": "1d"
},
"local": {
"usernameField": "email",
"passwordField": "password"
},
"oauth": {
"google": {
"key": "xxx.apps.googleusercontent.com",
"secret": "ASDFGgh"
}
}
},
}
更新 1
通过在Authorized redirect URIs
中添加https://localhost/oauth/google/callback
解决了问题。
现在网站重定向到Select Account
页面。
单击我的帐户后,网站将重定向到https://localhost/oauth/google/callback?code=4/abcd-xxx-xxxxx-xxx&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20openid&authuser=0&hd=myDomain.com&prompt=consent
更新 2
更新了 local.json 并添加了redirect_uri
字段
"oauth": {
"redirect": "/",
"google": {
"redirect_uri": "http://localhost:3030/auth/google/callback", // add here
"key": "abcd.googleusercontent.com",
"secret": "xxxx",
"scope": [
"email",
"profile",
"openid"
],
"nonce": true
}
}
它现在可以重定向到http://localhost:3030/auth/google/callback?code=xxx&scope=email+profile+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile+openid&authuser=0&hd=myDomain.com&prompt=consent#
更新 3
现在网站重定向到https://localhost/oauth/google/authenticate#
,我知道它应该是https://localhost:3030/oauth/google/authenticate
,但我不知道如何以及在哪里 Feather/Google Cloud平台可以设置
更新 4
终于成功重定向到www.google.com#error=Field%20password%20does%20not%20exist.%20(required)
,这是一种错误吗?
"oauth": {
"redirect": "www.google.com",
"google": {
"key": "<Google OAuth key>",
"secret": "<Google OAuth secret>",
"scope": [
"email",
"profile",
"openid"
],
"nonce": true,
"redirect_uri": "http://localhost:3030/oauth/google/callback",
"callback": "/oauth/google/authenticate"
}
}
重定向 URI 必须与您发送的位置完全匹配
您的应用正在发送
https://localhost/oauth/google/callback
您仅将以下内容添加为有效的重定向 uri
http://localhost:3030/auth/google/callback
解决方案是采用 https://localhost/oauth/google/callback 并将其添加为 Google Developer 控制台中的有效重定向 uri。
无法访问站点。
您的应用程序已告诉 google,您已准备好响应来自以下端点的授权服务器的授权代码
https://localhost/oauth/google/callback?code=4/abcd-xxx-xxxxx-xxx&scope=email%20profile%20https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20openid&authuser=0&hd=myDomain.com&prompt=consent
您的网站似乎无法处理该响应。 我会检查回调文件是否存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.