我在 Notion.so 上创建了一个集成
我使用以下 URL添加到 Notion获得了临时 OAuth 代码
上面的 URL,在从 Notion UI 授权后,现在给我下面的代码,
XXXXXXX-XXXXXXX
使用上面步骤中的代码来获取授权代码
POST https://api.notion.com/v1/oauth/token HTTP/1.1
Authorization: Basic XXXXXXXOnNlY3JldF9DeXp0d1A0TVNLZkZIY0XXXXXXXXX
Content-Type: application/json
Content-Length: 164
{
"grant_type": "authorization_code",
"code": "XXXXXX-XXXXX",
"redirect_uri": "http://localhost:8080/api/notion/auth/callback"
}
Run Code Online (Sandbox Code Playgroud)
这个回应在
{
"error": "invalid_grant"
}
Run Code Online (Sandbox Code Playgroud)
我错过了什么?
提前致谢!
尝试从两个调用中删除重定向 URL 以获取访问代码和授权令牌。当我尝试这样做时,这从服务器返回了成功响应。
app.get(auth_path, (req, res) => {
res.redirect(
//Documentation expects "${api_url}/v1/oauth/authorize?client_id=${process.env.NOTION_ID}&response_type=code&redirect_uri=${redirect_uri}"
encodeURI(`${api_url}/v1/oauth/authorize?client_id=${process.env.NOTION_ID}&response_type=code`),
);
});
`enter code here`app.get(access_token_path, ({query: {code}}, res) => {
//Exchange authorization code for access token
axios({
method:"post",
url:"https://api.notion.com/v1/oauth/token",
data: {
"code":code,
"grant_type": "authorization_code",
},
headers: {
"Authorization": `Basic ${auth_token}`,
"Content-Type": "application/json"
}
}).then((response) => {
res.sendStatus(200)
}).catch((err => {
console.log(err)
res.sendStatus(500)
}))
});
Run Code Online (Sandbox Code Playgroud)