我在这条指令中遵循这个流程:https://developers.google.com/identity/sign-in/web/server-side-flow通过谷歌进行身份验证。
在BackEnd服务器中,我使用lib : google-auth-lib
const { OAuth2Client } = require('google-auth-library');
async function login (code) {
const auth = new OAuth2Client(
googleConfig.clientId,
googleConfig.clientSecret,
googleConfig.redirect
);
const data = await auth.getToken(code);
}但目前我必须处理重定向url来匹配console.google项目中的配置。
我认为在这种情况下检查重定向url是不必要的。
那么如何禁用检查、重定向、url或任何想法?
发布于 2019-04-09 17:51:38
重定向uri验证检查是Google授权过程的一部分。您不能在web项目中禁用它。授权服务器需要知道将授权码返回到何处。如果您正在运行web应用程序,那么您将始终需要定义一个重定向uri。
另一方面,如果您正在运行服务器端应用程序或已安装的应用程序,那么您不应该使用web浏览器客户端,而应该使用不使用重定向uri的本地客户端。
此示例node quickstart旨在作为控制台应用程序运行,以访问google drive api。这可能会对你有帮助。
/**
* Create an OAuth2 client with the given credentials, and then execute the
* given callback function.
* @param {Object} credentials The authorization client credentials.
* @param {function} callback The callback to call with the authorized client.
*/
function authorize(credentials, callback) {
const {client_secret, client_id, redirect_uris} = credentials.installed;
const oAuth2Client = new google.auth.OAuth2(
client_id, client_secret, redirect_uris[0]);
// Check if we have previously stored a token.
fs.readFile(TOKEN_PATH, (err, token) => {
if (err) return getAccessToken(oAuth2Client, callback);
oAuth2Client.setCredentials(JSON.parse(token));
callback(oAuth2Client);
});
}https://stackoverflow.com/questions/55589873
复制相似问题