Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do i store other info in keychain except username and password #36

Closed
hejiaji opened this issue Oct 19, 2016 · 15 comments
Closed

How do i store other info in keychain except username and password #36

hejiaji opened this issue Oct 19, 2016 · 15 comments

Comments

@hejiaji
Copy link

hejiaji commented Oct 19, 2016

could it support to store other custom property like 'token', 'certification' or any other info rather than username and password?

As i see now it only supports these two properties which is a restriction to us

@hejiaji
Copy link
Author

hejiaji commented Oct 19, 2016

@oblador @vonovak

@vonovak
Copy link
Collaborator

vonovak commented Oct 19, 2016

You can serialize what you need to json and save it as the password. Then
you just deserialize the password.

On Oct 19, 2016 07:56, "Jeremy He" notifications@github.com wrote:

@oblador https://github.com/oblador @vonovak
https://github.com/vonovak


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#36 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABfmw6r1AylmQye-T3rWA6LMuKm3_I6Zks5q1bEqgaJpZM4Kalor
.

@hejiaji
Copy link
Author

hejiaji commented Oct 20, 2016

Ok, makes no sense to me, but seems like it's a only way

@vonovak vonovak changed the title How do i store other info in keyChian except username and password How do i store other info in keychain except username and password Mar 22, 2017
@danny-does-stuff
Copy link

I would love to have a feature like this. Storing key-value pairs would be a huge plus. I wish there was a function like Keychain.setValueForKey('myKey', 'myValue'), and then you can get that value with something like Keychain.getValueForKey('myKey'). Right now you have to store pairs of data of usernames and passwords which is not optimal for simply storing a token or a password by itself.

@hejiaji
Copy link
Author

hejiaji commented May 18, 2017

@dannyharding10 That's the exact feature i wanted

@leomeloxp
Copy link

Is there an actual practical difference between the two?

  • Keychain.setGenericPassword(username, password)
  • Keychain.setValueForKey('myKey', 'myValue')

I believe you can achieve the same end result by just using the generic password approach. I'm interested to know any challenges you find with this though, as this is one of the use cases I'm about to implement on an app.

@danny-does-stuff
Copy link

One challenge would be if your app interfaced with multiple APIs and it had to store a token for each one. You could only store one or two in the generic password. There would be ways to get around this, but they're not great solutions because it would make the code hard to understand. I ended up using the generic password myself because I only had to store one token, but this is still not optimal because generic password is meant for storing a username and a password pair.

@dani-mp
Copy link

dani-mp commented Sep 13, 2017

I agree with you, guys. It'd be great to have a simple API to store a key-value pair.

@MacKentoch
Copy link

As answered @vonovak you can just serialize your data (like JSON.stringify) to store any key-value data.

@dani-mp
Copy link

dani-mp commented Sep 13, 2017

Hey, @MacKentoch, thanks for answering.

My problem is not storing an object, but to store some info (a string, a stringified object...) under a certain key so I can retrieve it later, easily. What I'm doing right now is:

Keychain.setInternetCredentials('KEY', 'RANDOM_STUFF', 'value').then(() => console.log('Done'))
Keychain.getInternetCredentials('KEY').then(({ password }) => console.log('Got it', password))

but ideally we need

Keychain.setValueForKey('KEY', 'value').then(() => console.log('Done'))
Keychain.getValueForKey('KEY').then(value => console.log('Got it', value))

I don't know if I'm doing it in a good way, or if there is a better one with the current API.

Thanks.

@MacKentoch
Copy link

@danielmartinprieto I had this kind of need.

I just used optional parameter service of genericPasswordmethods as a KEY.
My data (JSON version of an array of object) was the VALUE

   function getGenericPassword(
        service?: string
    ): Promise<boolean | {service: string, username: string, password: string}>;

    function setGenericPassword(
        username: string,
        password: string,
        service?: string
    ): Promise<boolean>;

@dani-mp
Copy link

dani-mp commented Sep 13, 2017

Cool!

I think I will use your version because I find setGenericPassword for a service more semantically correct for my needs than setInternetCredentials for a server.

Thanks!

@Palisand
Copy link

So guys... is this a wontfix?

@ronilitman
Copy link

This can be very helpful.

@vonovak
Copy link
Collaborator

vonovak commented May 19, 2019

closing, as the question is answered in #36 (comment)

@vonovak vonovak closed this as completed May 19, 2019
Repository owner locked and limited conversation to collaborators May 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants