[英]How to Store OAuth Credentials With Gnome Keyring
I'm trying to build a simple Vala/Gtk Twitter app, and I've managed to send tweets; 我正在尝试构建一个简单的Vala / Gtk Twitter应用程序,并且设法发送了推文。 however, the user has to authenticate every time, which entails going to a URL, clicking to give my App permission to post, copying the PIN, and pasting said PIN into my App.
但是,用户每次都必须进行身份验证,这需要转到URL,单击以授予我的应用发布权限,复制PIN,然后将所述PIN粘贴到我的应用中。 For each tweet.
对于每条推文。
I'd like to store this authentication information in the GNOME Keyring; 我想将此身份验证信息存储在GNOME密钥环中; however, I barely know anything about OAuth and I know nothing about the Keyring.
但是,我对OAuth几乎一无所知,对Keyring也一无所知。
How can I store OAuth data into the Gnome Keyring? 如何将OAuth数据存储到Gnome密钥环中? I'll accept answers in any language, although bonus points will be awarded for Vala answers.
我将接受任何语言的答案,尽管Vala答案会获得加分。 :)
:)
You can use libsecret library which communicates with "Secret Service" through Dbus protocol . 您可以使用libsecret库,该库通过Dbus协议与“秘密服务”进行通信。
First you need to define a password schema , which will be used later for token store/extraction . 首先,您需要定义一个密码架构,以后将用于令牌存储/提取。
Vala example : Vala示例:
var example_schema = new Secret.Schema ("org.yor_schema.name",Secret,SchemaFlags.NONE,
"number", Secret.SchemaAttributeType.INTEGER,
"string", Secret.SchemaAttributeType.STRING);
Now you should store your token : 现在,您应该存储令牌:
var attributes = new GLib.HashTable<string,string> ();
attributes["number"] = "18";
attributes["string"] = "Hello";
Secret.password_storev.begin(example_schema,attributes,Secret.COLLECTION_DFAULT,
"Label","Token",null,(obj,async_res) => {
bool res = Secret.password_store.end(async_res);
/* Password has been stored - do something ... */
});
To extract stored token : 要提取存储的令牌:
var attributes = new GLib.HashTable<string,string> ();
attributes["number"] = "18";
attributes["string"] = "Hello";
Secret.password_lookupv.begin(example_schema,attributes,null,(obj,async_res) => {
String token = Secret.password_lookup.end(async_res);
});
The package name called libsecret-1
. 软件包名称为
libsecret-1
。
To compile , add following flag to your makefile . 要进行编译,请将以下标志添加到您的makefile中。
AM_VALAFLAGS = \
--pkg=libsecret-1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.