首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >mendeley Python中的身份验证问题

mendeley Python中的身份验证问题
EN

Stack Overflow用户
提问于 2017-12-12 16:28:59
回答 2查看 374关注 0票数 4

我在看这里的门德利博士。我正在尝试在我的控制台中获取数据,我正在使用本教程中的以下代码

代码语言:javascript
复制
from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

现在我不明白在最后一行代码中auth_response将来自何处?有人知道吗?谢谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-02-12 16:47:15

我能够使用下面的代码进行实验并使其工作,完全自动化。无用户干预

代码语言:javascript
复制
client_id = 1
client_secret = "XXXXXXXXX"

redirect_uri = "http://localhost:8080/testing"

from mendeley import Mendeley

# These values should match the ones supplied when registering your application.
mendeley = Mendeley(client_id, redirect_uri=redirect_uri)

auth = mendeley.start_implicit_grant_flow()

# The user needs to visit this URL, and log in to Mendeley.
login_url = auth.get_login_url()

import requests

res = requests.post(login_url, allow_redirects = False, data = {
    'username': 'xxxx@gmail.com',
    'password': 'xxxxx'
})

auth_response = res.headers['Location']

# After logging in, the user will be redirected to a URL, auth_response.
session = auth.authenticate(auth_response)

print(session.files.list().items)

最后一行打印[<mendeley.models.files.File object at 0x1115b5400>],这意味着访问如果工作

票数 6
EN

Stack Overflow用户

发布于 2018-02-11 01:15:00

据我所知,auth_response是由用户/服务器提供的。例如,我在github上找到了一个很好的代码块(完整的源代码在这里:链接):

代码语言:javascript
复制
@app.route('/oauth')
def auth_return():
    auth = mendeley.start_authorization_code_flow(state=session['state'])
    mendeley_session = auth.authenticate(request.url)

    session.clear()
    session['token'] = mendeley_session.token

    return redirect('/listDocuments')

如您所见,作者似乎要将客户机重定向回原始request.url。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47777288

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档