You can use libsecret library which communicates with "Secret Service" through Dbus protocol .
First you need to define a password schema , which will be used later for token store/extraction .
Vala example :
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
.
To compile , add following flag to your makefile .
AM_VALAFLAGS = \
--pkg=libsecret-1