我正在致力于存储oauth2凭据,以便以后可以创建服务。oAuth2凭据存储为unicode
目前我的模式是这样的:
from django.db import models
from oauth2client.contrib.django_util.models import CredentialsField
from south.modelsinspector import add_introspection_rules
class oAuth(models.Model):
siteid = models.CharField(max_length=100L, primary_key=True)
credential = CredentialsField()
add_introspection_rules([],["^oauth2client\.contrib\.django_util\.models\.CredentialsField"])
,当我尝试保存我的凭据:
credential = flow.step2_exchange(code)
storage = DjangoORMStorage(oAuth, 'siteid', site_id, 'credential')
storage.put(credential)
在我的数据库我有被存储在一个Unicode字符串,然后不能转换到一个oauth对象使用:
storage = DjangoORMStorage(oAuth, 'siteid', site_id, 'credential')
credential = storage.get()
return credential
我得到的凭据是先前存储的unicode,我只是不能执行.authorize方法,这是我需要做的,
我得到了困惑的地方?
我的问题是,当我调用storage.get()时,我得到的unicode不是原始的oAuth对象,所以我无法调用'.authorize()',我不确定是否需要使用unicode并构建一个oAuth对象,但我无法找到任何关于该对象的说明。 我检查了编码,它是cp1252但是我所有的其他表都是相同的编码,其他所有的东西似乎都正常工作 –
忽略我以前的评论。我现在看到'DjangoORMStorage'来自lib本身。我没有想法。 :-) –
寻找[客户端存储](https://github.com/google/oauth2client/blob/master/oauth2client/client.py)它似乎像.get()存储实际上必须返回一个oauth对象这就是为什么我不明白它是如何返回unicode的 –