【发布时间】:2017-12-01 06:19:48
【问题描述】:
我正在尝试在第一次安装/身份验证时将 shopify 访问令牌存储在 django 视图中(在他们创建帐户并连接到数据库之前)。
我是 django 的新手,所以请善待。
如何存储此访问令牌以供以后使用?它可以存储在“会话”中吗?已经了吗?
这是我的repo 和 python 视图:
def finalize(request):
shop_url = request.GET['shop']
auth_code = request.GET['code']
hashed = request.GET['hmac']
ts = request.GET['timestamp']
print("shopURL", shop_url)
print("success request")
try:
r = requests.post('https://'+shop_url+'/admin/oauth/access_token', data = {'client_id':'xx','client_secret':'xx','code':auth_code})
print("request response > > > > ", r.json())
this_response = r.json()
print(this_response["access_token"],"this_response[access_token]")
# >>>>>> STORE THIS TOKEN SOMEWHERE?
request.session['shopify'] = {
"shop_url": shop_url,
"access_token": this_response["access_token"]
}
except Exception:
messages.error(request, "Could not log in to Shopify store.")
return redirect(reverse('shopify_app_login'))
messages.info(request, "Logged in to shopify store.")
response = redirect(_return_address(request))
request.session.pop('return_to', None)
return response
【问题讨论】:
-
您要跨会话存储访问令牌还是仅存储当前会话?
-
跨会话.. 但即使我重新访问该站点 - 我每次都必须重新验证.. 某些东西不起作用@kshikama