Documentation ¶
Index ¶
- type Authorizer
- func (c *Authorizer) AuthorizationURL() (*url.URL, error)
- func (c *Authorizer) CSRFToken() *uuid.UUID
- func (c *Authorizer) ExchangeAuthorizationCode(code string) (token *types.AuthorizedUser, err error)
- func (c *Authorizer) HTTP() (*http.Client, error)
- func (c *Authorizer) SetAuthorizing(auth *types.AuthorizingUser)
- func (c *Authorizer) SetToken(token *types.AuthorizedUser)
- func (c *Authorizer) UserID() (*string, error)
- type Storage
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Authorizer ¶
type Authorizer struct {
// contains filtered or unexported fields
}
Authorizer is the structure that manages the OAuth2 authorization process. It depends on a `Storage` where the tokens are stored during the various exchanges.
func NewAuthorizer ¶
func NewAuthorizer(db Storage, clientID, clientSecret, redirectURL string) *Authorizer
NewAuthorizer creates a new Authorizer. The created client is already configured for requesting the correct scopes and make authenticathed/authorized requests to the fitbit API. The db parameter must be a valid implementation of the Storage interface.
func (*Authorizer) AuthorizationURL ¶
func (c *Authorizer) AuthorizationURL() (*url.URL, error)
AuthorizationURL returns the URL where to redirect the user where it will be asked for giving the permissions for the various scopes
func (*Authorizer) CSRFToken ¶
func (c *Authorizer) CSRFToken() *uuid.UUID
CSRFToken returns the CSRF code associated with this session
func (*Authorizer) ExchangeAuthorizationCode ¶
func (c *Authorizer) ExchangeAuthorizationCode(code string) (token *types.AuthorizedUser, err error)
ExchangeAuthorizationCode exchanges the authorization code for the access and refresh tokens. In a Server Application Type, this request should be authenticated https://dev.fitbit.com/build/reference/web-api/developer-guide/authorization/#Authorization-Code-Grant-Flow-with-PKCE See step 4
This method also saves the exchanged token inside the *Authorizer structure. This token is later used for creating the HTTP client (see HTTP method).
func (*Authorizer) HTTP ¶
func (c *Authorizer) HTTP() (*http.Client, error)
Return an HTTP client that uses the specified token for authenticating It handles all the refresh-token stuff, and it updates inside the db The values for the user that's this *Authorizer
func (*Authorizer) SetAuthorizing ¶
func (c *Authorizer) SetAuthorizing(auth *types.AuthorizingUser)
SetAuthorizing sets the parameters required during the autorization process
func (*Authorizer) SetToken ¶
func (c *Authorizer) SetToken(token *types.AuthorizedUser)
SetToken sets the token inside the Authorizer. From the types.AuthorizedUser to the oauth2.Token representation (privately used).
func (*Authorizer) UserID ¶
func (c *Authorizer) UserID() (*string, error)
UserID returns the ID of the users that authorized this client Returns an error if the fitbitClient is not authorized
type Storage ¶
type Storage interface { // InsertAuthorizingUser creates a new AuthorizingUser. // An AuthorizingUser is an user in the process of giving the // authorization to the fitbit-API-based application. InsertAuthorizingUser(*types.AuthorizingUser) error // UpsertAuthorizedUser creates or updates an AuthorizedUser. // It creates the user if it's not present in the storage. It updates its // attributes if the very same user is already present in the storage. // An AuthorizedUser is an user that completed the Authorization phase // that means it transitioned from the state of AuthorizingUser to the // state of AuthorizedUser. UpsertAuthorizedUser(*types.AuthorizedUser) error // AuthorizedUser returns a pointer to types.AuthorizedUser // given the accessToken. AuthorizedUser(accessToken string) (*types.AuthorizedUser, error) // AuthorizingUser returns a pointer to the types.AuthorizingUser // given it's unique identifier (any ID - in DB implementation often // a primary key). AuthorizingUser(id string) (*types.AuthorizingUser, error) }
Storage is the interface to implement for implementing the persistence layer required by the fitbit client.
Directories ¶
Path | Synopsis |
---|---|
Package api contains the implementation of the REST [Fitbit Web API][1].
|
Package api contains the implementation of the REST [Fitbit Web API][1]. |
Package types contains all the types that represent a response given by the Fitbit API.
|
Package types contains all the types that represent a response given by the Fitbit API. |