auth

package
v0.0.0-...-c5aa16e Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2020 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package auth uses the `oauth2 authorization_code` flow to authenticate with Arduino

If you have the username and password of a user, you can just instantiate a client with sane defaults:

client := auth.New()

and then call the Token method to obtain a Token object with an AccessToken and a RefreshToken

token, err := client.Token(username, password)

If instead you already have a token but want to refresh it, just call

token, err := client.refresh(refreshToken)

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckDeviceAuth

func CheckDeviceAuth(authURL, clientID, deviceCode string) (token string, err error)

func Init

func Init()

Init initialize correctly HTTP client

Types

type Config

type Config struct {
	// CodeURL is the endpoint to redirect to obtain a code
	CodeURL string

	// TokenURL is the endpoint where you can request an access code
	TokenURL string

	// ClientID is the client id you are using
	ClientID string

	// RedirectURI is the redirectURI where the oauth process will redirect. It's only required since the oauth system checks for it, but we intercept the redirect before hitting it
	RedirectURI string

	// Scopes is a space-separated list of scopes to require
	Scopes string
}

Config contains the variables you may want to change

func New

func New() *Config

New returns an auth configuration with sane defaults

func (*Config) Refresh

func (c *Config) Refresh(token string) (*Token, error)

Refresh exchanges a token for a new one

func (*Config) Token

func (c *Config) Token(user, pass string) (*Token, error)

Token authenticates with the given username and password and returns a Token object

type DeviceCode

type DeviceCode struct {
	DeviceCode              string `json:"device_code"`
	UserCode                string `json:"user_code"`
	VerificationURI         string `json:"verification_uri"`
	ExpiresIn               int    `json:"expires_in"`
	Interval                int    `json:"interval"`
	VerificationURIComplete string `json:"verification_uri_complete"`
}

func StartDeviceAuth

func StartDeviceAuth(authURL, clientID string) (data DeviceCode, err error)

StartDeviceAuth request with POST auth using clientID

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
	Get(url string) (resp *http.Response, err error)
}

HTTPClient interface

type Token

type Token struct {
	// Access is the token to use to authenticate requests
	Access string `json:"access_token"`

	// Refresh is the token to use to request another access token. It's only returned if one of the scopes is "offline"
	Refresh string `json:"refresh_token"`

	// TTL is the number of seconds that the tokens will last
	TTL int `json:"expires_in"`

	// Scopes is a space-separated list of scopes associated to the access token
	Scopes string `json:"scope"`

	// Type is the type of token
	Type string `json:"token_type"`
}

Token is the response of the two authentication functions

Jump to

Keyboard shortcuts

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