An open API service indexing awesome lists of open source software.

https://github.com/plumber-cd/go-credentials

Cross Platform Go Credentials Provider
https://github.com/plumber-cd/go-credentials

credentials go golang keychain keyring

Last synced: 6 months ago
JSON representation

Cross Platform Go Credentials Provider

Awesome Lists containing this project

README

          

# go-credentials
Cross Platform Go Credentials Provider

This simple library provides common interface for working with credentials.

By default it uses the following interfaces:

- MacOS: https://github.com/keybase/go-keychain
- Linux: https://github.com/keybase/dbus
- Windows: https://github.com/danieljoos/wincred

You can substitute it with your own interface per platform.

# Example

```go
package main

import (
"fmt"

"github.com/plumber-cd/go-credentials"
)

func main() {
domain := &credentials.Domain{
Service: "My App Name",
AccessGroup: "github.com/plumber-cd/go-credentials", // Define some unique for your app instance value
}

if err := credentials.SetDomain(domain); err != nil {
panic(err)
}

if err := err = credentials.Create("http://example.com", "", "password"); err != nil {
panic(err)
}

name, secret, err := credentials.Retrieve("http://example.com")
if err != nil {
panic(err)
}
fmt.Printf("Name: %s\n", name)
fmt.Printf("Secret: %s\n", secret)

if err := credentials.Update("http://example.com", "new title", "new password"); err != nil {
panic(err)
}

if err := credentials.Delete("http://example.com"); err {
panic(err)
}
}
```

# Custom provider

You need to create new `struct` than implements `credentials.Provider` interface. Somewhere in your app, you then will need to:

```go
package main

import "github.com/plumber-cd/go-credentials"

func init() {
credentials.Current = &MyCustomProvider{}
}
```

That's it. All other code that is using this same library - will now use your custom provider instead of default.