oauthdb

package
v0.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 7, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package oauthdb implements ClientStore and TokenStore from gopkg.in/oauth2.v3 using Go's sql.DB

The implementation is tested with SQLite, but should work with other SQL engines as we attempt to use platform agnostic SQL queries.

A few extra operations on ClientStore have been added though, such as Set and GetByUserId. These were needed for ourusecase as we're mutating the oauth clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ClientStore

type ClientStore struct {
	oauth2.ClientStore
	// contains filtered or unexported fields
}

ClientStore wraps oauth2.ClientStore with an underlying *sql.DB provided from NewClientStoreDB

func NewClientStoreDB

func NewClientStoreDB(connString string) (*ClientStore, error)

NewClientStoreDB returns a ClientStore wrapped with the underlying sql.DB.

In order to call this method register your driver.

import (
    "database/sql"
    _ "github.com/mattn/go-sqlite3"
   "github.com/moov-io/pkg/oauthdb"
)

func main() {
    db, err := oauthdb.NewClientStoreDB("file:client_store.db")
}

connString is a Data Source Name (DSN), See the respective driver documentation for parameters.

func (*ClientStore) Close

func (cs *ClientStore) Close() error

Close shuts down connections to the underlying database

func (*ClientStore) DeleteByID

func (cs *ClientStore) DeleteByID(id string) error

DeleteByID removes the oauth2.ClientInfo for the provided id.

func (*ClientStore) GetByID

func (cs *ClientStore) GetByID(id string) (oauth2.ClientInfo, error)

GetByID returns an oauth2.ClientInfo if the ID matches id.

func (*ClientStore) GetByUserID

func (cs *ClientStore) GetByUserID(userId string) ([]oauth2.ClientInfo, error)

GetByUserID returns an array of oauth2.ClientInfo which have a UserID mathcing userId. If return values are nil that means no matching records were found.

func (*ClientStore) Set

func (cs *ClientStore) Set(id string, cli oauth2.ClientInfo) error

Set writes the oauth2.ClientInfo to the underlying database.

type TokenStore

type TokenStore struct {
	oauth2.TokenStore
	// contains filtered or unexported fields
}

TokenStore wraps oauth2.TokenStore with an underlying *sql.DB provided from NewTokenStoreDB

func NewTokenStoreDB

func NewTokenStoreDB(connString string) (*TokenStore, error)

NewTokenStoreDB returns a TokenStore wrapped with the underlying sql.DB.

In order to call this method register your driver.

import (
    "database/sql"
    _ "github.com/mattn/go-sqlite3"
   "github.com/moov-io/pkg/oauthdb"
)

func main() {
    db, err := oauthdb.NewTokenStoreDB("file:token_store.db")
}

connString is a Data Source Name (DSN), See the respective driver documentation for parameters.

func (*TokenStore) Close

func (ts *TokenStore) Close() error

Close shuts down connections to the underlying database

func (*TokenStore) Create

func (ts *TokenStore) Create(info oauth2.TokenInfo) error

Create writes an oauth2.TokenInfo into the underlying database.

If an existing token exists (matching code, access, and refresh) then that row will be replaced by the incoming token. This is done to update the userId on a given token.

func (*TokenStore) GetByAccess

func (ts *TokenStore) GetByAccess(access string) (oauth2.TokenInfo, error)

GetByAccess use the access token for token information data

func (*TokenStore) GetByCode

func (ts *TokenStore) GetByCode(code string) (oauth2.TokenInfo, error)

GetByCode use the authorization code for token information data TODO(adam): make sure this is protected by a userId check

func (*TokenStore) GetByRefresh

func (ts *TokenStore) GetByRefresh(refresh string) (oauth2.TokenInfo, error)

GetByRefresh use the refresh token for token information data

func (*TokenStore) RemoveByAccess

func (ts *TokenStore) RemoveByAccess(access string) error

RemoveByAccess use the access token to delete the token information

func (*TokenStore) RemoveByCode

func (ts *TokenStore) RemoveByCode(code string) error

RemoveByCode use the authorization code to delete the token information TODO(adam): make sure this is guardded by a userId check

func (*TokenStore) RemoveByRefresh

func (ts *TokenStore) RemoveByRefresh(refresh string) error

RemoveByRefresh use the refresh token to delete the token information

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL