Documentation
¶
Overview ¶
Package auth provides primitives to interact with the openapi HTTP API.
Code generated by github.com/oapi-codegen/oapi-codegen/v2 version v2.5.1 DO NOT EDIT.
Index ¶
- Constants
- Variables
- func CredentialsPath() (string, error)
- func NewPostOAuth2TokenRefreshRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)
- func NewPostOAuth2TokenRefreshRequestWithFormdataBody(server string, body PostOAuth2TokenRefreshFormdataRequestBody) (*http.Request, error)
- func NewPostTokenRequestWithBody(server string, params *PostTokenParams, contentType string, body io.Reader) (*http.Request, error)
- func NewPostTokenRequestWithFormdataBody(server string, params *PostTokenParams, body PostTokenFormdataRequestBody) (*http.Request, error)
- type AccessTokenResponse
- type Client
- func (c *Client) PostOAuth2TokenRefreshWithBody(ctx context.Context, contentType string, body io.Reader, ...) (*http.Response, error)
- func (c *Client) PostOAuth2TokenRefreshWithFormdataBody(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, ...) (*http.Response, error)
- func (c *Client) PostTokenWithBody(ctx context.Context, params *PostTokenParams, contentType string, ...) (*http.Response, error)
- func (c *Client) PostTokenWithFormdataBody(ctx context.Context, params *PostTokenParams, ...) (*http.Response, error)
- type ClientIdQuery
- type ClientInterface
- type ClientOption
- type ClientWithResponses
- func (c *ClientWithResponses) PostOAuth2TokenRefreshWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, ...) (*PostOAuth2TokenRefreshResponse, error)
- func (c *ClientWithResponses) PostOAuth2TokenRefreshWithFormdataBodyWithResponse(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, ...) (*PostOAuth2TokenRefreshResponse, error)
- func (c *ClientWithResponses) PostTokenWithBodyWithResponse(ctx context.Context, params *PostTokenParams, contentType string, ...) (*PostTokenResponse, error)
- func (c *ClientWithResponses) PostTokenWithFormdataBodyWithResponse(ctx context.Context, params *PostTokenParams, ...) (*PostTokenResponse, error)
- type ClientWithResponsesInterface
- type Credentials
- type CredentialsService
- type CredentialsServiceOptions
- type DeviceAuthorizationRequest
- type DeviceAuthorizationResponse
- type DeviceCodeQuery
- type DeviceTokenPollRequest
- type FileCredentialStore
- type GrantType
- type GrantTypeQuery
- type HttpRequestDoer
- type OAuth2ErrorResponse
- type PostOAuth2TokenRefreshFormdataRequestBody
- type PostOAuth2TokenRefreshResponse
- type PostTokenFormdataBody
- type PostTokenFormdataRequestBody
- type PostTokenParams
- type PostTokenResponse
- type RefreshTokenRequest
- type RefreshTokenRequestGrantType
- type RequestEditorFn
- type TokenExpiry
Constants ¶
const (
BasicAuthScopes = "BasicAuth.Scopes"
)
Variables ¶
var ( ErrTokenMalformed = errors.New("token is malformed") ErrTokenNoExpiry = errors.New("token has no expiration claim") )
var ErrCredentialsNotFound = errors.New("credentials not found")
ErrCredentialsNotFound is returned when no credentials file exists.
Functions ¶
func CredentialsPath ¶
CredentialsPath returns the default path for stored API credentials.
func NewPostOAuth2TokenRefreshRequestWithBody ¶
func NewPostOAuth2TokenRefreshRequestWithBody(server string, contentType string, body io.Reader) (*http.Request, error)
NewPostOAuth2TokenRefreshRequestWithBody generates requests for PostOAuth2TokenRefresh with any type of body
func NewPostOAuth2TokenRefreshRequestWithFormdataBody ¶
func NewPostOAuth2TokenRefreshRequestWithFormdataBody(server string, body PostOAuth2TokenRefreshFormdataRequestBody) (*http.Request, error)
NewPostOAuth2TokenRefreshRequestWithFormdataBody calls the generic PostOAuth2TokenRefresh builder with application/x-www-form-urlencoded body
func NewPostTokenRequestWithBody ¶
func NewPostTokenRequestWithBody(server string, params *PostTokenParams, contentType string, body io.Reader) (*http.Request, error)
NewPostTokenRequestWithBody generates requests for PostToken with any type of body
func NewPostTokenRequestWithFormdataBody ¶
func NewPostTokenRequestWithFormdataBody(server string, params *PostTokenParams, body PostTokenFormdataRequestBody) (*http.Request, error)
NewPostTokenRequestWithFormdataBody calls the generic PostToken builder with application/x-www-form-urlencoded body
Types ¶
type AccessTokenResponse ¶
type AccessTokenResponse struct {
AccessToken string `json:"access_token"`
// ExpiresIn Access token lifetime in seconds.
ExpiresIn int `json:"expires_in"`
// RefreshToken Optional refresh token for later renewal (Cognito).
RefreshToken *string `json:"refresh_token,omitempty"`
TokenType string `json:"token_type"`
}
AccessTokenResponse OAuth 2 access token success response (RFC 6749 §5.1).
type Client ¶
type Client struct {
// The endpoint of the server conforming to this interface, with scheme,
// https://api.deepmap.com for example. This can contain a path relative
// to the server, such as https://api.deepmap.com/dev-test, and all the
// paths in the swagger spec will be appended to the server.
Server string
// Doer for performing requests, typically a *http.Client with any
// customized settings, such as certificate chains.
Client HttpRequestDoer
// A list of callbacks for modifying requests which are generated before sending over
// the network.
RequestEditors []RequestEditorFn
}
Client which conforms to the OpenAPI3 specification for this service.
func NewClient ¶
func NewClient(server string, opts ...ClientOption) (*Client, error)
Creates a new Client, with reasonable defaults
func (*Client) PostOAuth2TokenRefreshWithBody ¶
func (*Client) PostOAuth2TokenRefreshWithFormdataBody ¶
func (c *Client) PostOAuth2TokenRefreshWithFormdataBody(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
func (*Client) PostTokenWithBody ¶
func (*Client) PostTokenWithFormdataBody ¶
func (c *Client) PostTokenWithFormdataBody(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
type ClientInterface ¶
type ClientInterface interface {
// PostOAuth2TokenRefreshWithBody request with any body
PostOAuth2TokenRefreshWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
PostOAuth2TokenRefreshWithFormdataBody(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// PostTokenWithBody request with any body
PostTokenWithBody(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
PostTokenWithFormdataBody(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
}
The interface specification for the client above.
type ClientOption ¶
ClientOption allows setting custom parameters during construction
func WithHTTPClient ¶
func WithHTTPClient(doer HttpRequestDoer) ClientOption
WithHTTPClient allows overriding the default Doer, which is automatically created using http.Client. This is useful for tests.
func WithRequestEditorFn ¶
func WithRequestEditorFn(fn RequestEditorFn) ClientOption
WithRequestEditorFn allows setting up a callback function, which will be called right before sending the request. This can be used to mutate the request.
type ClientWithResponses ¶
type ClientWithResponses struct {
ClientInterface
}
ClientWithResponses builds on ClientInterface to offer response payloads
func NewClientWithResponses ¶
func NewClientWithResponses(server string, opts ...ClientOption) (*ClientWithResponses, error)
NewClientWithResponses creates a new ClientWithResponses, which wraps Client with return type handling
func (*ClientWithResponses) PostOAuth2TokenRefreshWithBodyWithResponse ¶
func (c *ClientWithResponses) PostOAuth2TokenRefreshWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
PostOAuth2TokenRefreshWithBodyWithResponse request with arbitrary body returning *PostOAuth2TokenRefreshResponse
func (*ClientWithResponses) PostOAuth2TokenRefreshWithFormdataBodyWithResponse ¶
func (c *ClientWithResponses) PostOAuth2TokenRefreshWithFormdataBodyWithResponse(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
func (*ClientWithResponses) PostTokenWithBodyWithResponse ¶
func (c *ClientWithResponses) PostTokenWithBodyWithResponse(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
PostTokenWithBodyWithResponse request with arbitrary body returning *PostTokenResponse
func (*ClientWithResponses) PostTokenWithFormdataBodyWithResponse ¶
func (c *ClientWithResponses) PostTokenWithFormdataBodyWithResponse(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
type ClientWithResponsesInterface ¶
type ClientWithResponsesInterface interface {
// PostOAuth2TokenRefreshWithBodyWithResponse request with any body
PostOAuth2TokenRefreshWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
PostOAuth2TokenRefreshWithFormdataBodyWithResponse(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
// PostTokenWithBodyWithResponse request with any body
PostTokenWithBodyWithResponse(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
PostTokenWithFormdataBodyWithResponse(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
}
ClientWithResponsesInterface is the interface specification for the client with responses above.
type Credentials ¶
type Credentials struct {
AccessToken string `json:"access_token"`
ExpiresAt time.Time `json:"expires_at"`
RefreshToken *string `json:"refresh_token,omitempty"`
}
Credentials represents the JWT credentials used to access the IFC API.
type CredentialsService ¶
type CredentialsService struct {
*ClientWithResponses
Credentials *Credentials
// contains filtered or unexported fields
}
CredentialsService manages getting and refreshing JWT credentials.
func NewCredentialsService ¶
func NewCredentialsService(opts ...CredentialsServiceOptions) (*CredentialsService, error)
NewCredentialsService creates a new CredentialsService with the given options.
func (*CredentialsService) Login ¶
func (s *CredentialsService) Login(ctx context.Context) error
Login performs the full device flow: request codes, prompt user, poll for tokens.
func (*CredentialsService) ReadCredentials ¶
func (s *CredentialsService) ReadCredentials() error
ReadCredentials reads API credentials stored locally.
func (*CredentialsService) RefreshTokens ¶
func (s *CredentialsService) RefreshTokens(ctx context.Context) error
RefreshTokens exchanges a refresh token for new access tokens via Cognito.
func (*CredentialsService) WriteCredentials ¶
func (s *CredentialsService) WriteCredentials() error
WriteCredentials writes API credentials to file locally.
type CredentialsServiceOptions ¶
type CredentialsServiceOptions func(*CredentialsService) error
CredentialsServiceOptions are functional options that can be used to configure a CredentialsService.
func WithCredentialStore ¶
func WithCredentialStore(store *FileCredentialStore) CredentialsServiceOptions
WithCredentialStore sets the credential store (for tests).
type DeviceAuthorizationRequest ¶
type DeviceAuthorizationRequest struct {
// ClientId Public OAuth 2 client identifier.
ClientId string `json:"client_id"`
}
DeviceAuthorizationRequest defines model for DeviceAuthorizationRequest.
type DeviceAuthorizationResponse ¶
type DeviceAuthorizationResponse struct {
DeviceCode string `json:"device_code"`
// ExpiresIn Lifetime of the `device_code` in seconds.
ExpiresIn int `json:"expires_in"`
// Interval Minimum polling interval in seconds; client may increase on `slow_down`.
Interval int `json:"interval"`
UserCode string `json:"user_code"`
VerificationUri string `json:"verification_uri"`
// VerificationUriComplete Pre-filled verification URI (preferred for UX).
VerificationUriComplete *string `json:"verification_uri_complete,omitempty"`
}
DeviceAuthorizationResponse RFC 8628 §3.2 device authorization response.
type DeviceCodeQuery ¶
type DeviceCodeQuery = string
DeviceCodeQuery defines model for DeviceCodeQuery.
type DeviceTokenPollRequest ¶
type DeviceTokenPollRequest struct {
ClientId string `json:"client_id"`
DeviceCode string `json:"device_code"`
// GrantType A grant type to request.
GrantType GrantType `json:"grant_type"`
}
DeviceTokenPollRequest defines model for DeviceTokenPollRequest.
type FileCredentialStore ¶
type FileCredentialStore struct {
// contains filtered or unexported fields
}
FileCredentialStore reads and writes credentials as JSON under the user's config directory.
func NewFileCredentialStore ¶
func NewFileCredentialStore() (*FileCredentialStore, error)
NewFileCredentialStore creates a store at the default credentials path.
func NewFileCredentialStoreAt ¶
func NewFileCredentialStoreAt(path string) *FileCredentialStore
NewFileCredentialStoreAt creates a store at an explicit path (for tests).
func (*FileCredentialStore) Path ¶
func (s *FileCredentialStore) Path() string
Path returns the credentials file path.
func (*FileCredentialStore) Read ¶
func (s *FileCredentialStore) Read() (*Credentials, error)
Read loads credentials from disk.
func (*FileCredentialStore) Write ¶
func (s *FileCredentialStore) Write(credentials *Credentials) error
Write persists credentials to disk with restrictive permissions.
type GrantType ¶
type GrantType string
GrantType A grant type to request.
const (
UrnIetfParamsOauthGrantTypeDeviceCode GrantType = "urn:ietf:params:oauth:grant-type:device_code"
)
Defines values for GrantType.
type HttpRequestDoer ¶
Doer performs HTTP requests.
The standard http.Client implements this interface.
type OAuth2ErrorResponse ¶
type OAuth2ErrorResponse struct {
// Error Machine-readable error code. Observed values include
// `authorization_pending`, `slow_down`, `expired_token`, `invalid_grant`.
Error *string `json:"error,omitempty"`
// ErrorDescription Human-readable detail; may be empty.
ErrorDescription *string `json:"error_description,omitempty"`
}
OAuth2ErrorResponse OAuth 2 error response (RFC 6749 §5.2).
type PostOAuth2TokenRefreshFormdataRequestBody ¶
type PostOAuth2TokenRefreshFormdataRequestBody = RefreshTokenRequest
PostOAuth2TokenRefreshFormdataRequestBody defines body for PostOAuth2TokenRefresh for application/x-www-form-urlencoded ContentType.
type PostOAuth2TokenRefreshResponse ¶
type PostOAuth2TokenRefreshResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *AccessTokenResponse
JSONDefault *OAuth2ErrorResponse
}
func ParsePostOAuth2TokenRefreshResponse ¶
func ParsePostOAuth2TokenRefreshResponse(rsp *http.Response) (*PostOAuth2TokenRefreshResponse, error)
ParsePostOAuth2TokenRefreshResponse parses an HTTP response from a PostOAuth2TokenRefreshWithResponse call
func (PostOAuth2TokenRefreshResponse) Status ¶
func (r PostOAuth2TokenRefreshResponse) Status() string
Status returns HTTPResponse.Status
func (PostOAuth2TokenRefreshResponse) StatusCode ¶
func (r PostOAuth2TokenRefreshResponse) StatusCode() int
StatusCode returns HTTPResponse.StatusCode
type PostTokenFormdataBody ¶
type PostTokenFormdataBody struct {
// contains filtered or unexported fields
}
PostTokenFormdataBody defines parameters for PostToken.
type PostTokenFormdataRequestBody ¶
type PostTokenFormdataRequestBody PostTokenFormdataBody
PostTokenFormdataRequestBody defines body for PostToken for application/x-www-form-urlencoded ContentType.
type PostTokenParams ¶
type PostTokenParams struct {
// ClientId OAuth 2 `client_id`. Sent in both query and body by the client.
ClientId *ClientIdQuery `form:"client_id,omitempty" json:"client_id,omitempty"`
// DeviceCode Device code from step A. Required for step B (poll).
DeviceCode *DeviceCodeQuery `form:"device_code,omitempty" json:"device_code,omitempty"`
// GrantType Required for step B; must be the device code grant type.
GrantType *GrantTypeQuery `form:"grant_type,omitempty" json:"grant_type,omitempty"`
}
PostTokenParams defines parameters for PostToken.
type PostTokenResponse ¶
type PostTokenResponse struct {
Body []byte
HTTPResponse *http.Response
JSON200 *struct {
// contains filtered or unexported fields
}
JSON4XX *OAuth2ErrorResponse
}
func ParsePostTokenResponse ¶
func ParsePostTokenResponse(rsp *http.Response) (*PostTokenResponse, error)
ParsePostTokenResponse parses an HTTP response from a PostTokenWithResponse call
func (PostTokenResponse) Status ¶
func (r PostTokenResponse) Status() string
Status returns HTTPResponse.Status
func (PostTokenResponse) StatusCode ¶
func (r PostTokenResponse) StatusCode() int
StatusCode returns HTTPResponse.StatusCode
type RefreshTokenRequest ¶
type RefreshTokenRequest struct {
// ClientId Same public client_id as the device flow.
ClientId string `json:"client_id"`
GrantType RefreshTokenRequestGrantType `json:"grant_type"`
RefreshToken string `json:"refresh_token"`
}
RefreshTokenRequest Cognito `/oauth2/token` body for the refresh_token grant (RFC 6749).
type RefreshTokenRequestGrantType ¶
type RefreshTokenRequestGrantType string
RefreshTokenRequestGrantType defines model for RefreshTokenRequest.GrantType.
const (
RefreshToken RefreshTokenRequestGrantType = "refresh_token"
)
Defines values for RefreshTokenRequestGrantType.
type RequestEditorFn ¶
RequestEditorFn is the function signature for the RequestEditor callback function
type TokenExpiry ¶
type TokenExpiry struct {
ExpiresAt time.Time
ExpiresIn time.Duration // time remaining until expiry (negative if already expired)
IsExpired bool
}
TokenExpiry holds the parsed expiration details of a JWT.
func GetTokenExpiry ¶
func GetTokenExpiry(tokenString string) (*TokenExpiry, error)
GetTokenExpiry extracts the expiration time from a JWT access token without verifying the signature. This is safe for inspecting your own tokens where you trust the source but don't have the signing key handy (e.g. an opaque access token returned by an OAuth server).
If you DO have the signing key, use GetTokenExpiryVerified instead.