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.8.1 DO NOT EDIT.
Index ¶
- 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
- func (r PostOAuth2TokenRefreshResponse) ContentType() string
- func (r PostOAuth2TokenRefreshResponse) GetBody() []byte
- func (r PostOAuth2TokenRefreshResponse) GetJSON200() *AccessTokenResponse
- func (r PostOAuth2TokenRefreshResponse) GetJSONDefault() *OAuth2ErrorResponse
- func (r PostOAuth2TokenRefreshResponse) Status() string
- func (r PostOAuth2TokenRefreshResponse) StatusCode() int
- type PostToken200JSONResponseBody
- func (t PostToken200JSONResponseBody) AsAccessTokenResponse() (AccessTokenResponse, error)
- func (t PostToken200JSONResponseBody) AsDeviceAuthorizationResponse() (DeviceAuthorizationResponse, error)
- func (t *PostToken200JSONResponseBody) FromAccessTokenResponse(v AccessTokenResponse) error
- func (t *PostToken200JSONResponseBody) FromDeviceAuthorizationResponse(v DeviceAuthorizationResponse) error
- func (t PostToken200JSONResponseBody) MarshalJSON() ([]byte, error)
- func (t *PostToken200JSONResponseBody) MergeAccessTokenResponse(v AccessTokenResponse) error
- func (t *PostToken200JSONResponseBody) MergeDeviceAuthorizationResponse(v DeviceAuthorizationResponse) error
- func (t *PostToken200JSONResponseBody) UnmarshalJSON(b []byte) error
- type PostTokenFormdataBody
- func (t PostTokenFormdataBody) AsDeviceAuthorizationRequest() (DeviceAuthorizationRequest, error)
- func (t PostTokenFormdataBody) AsDeviceTokenPollRequest() (DeviceTokenPollRequest, error)
- func (t *PostTokenFormdataBody) FromDeviceAuthorizationRequest(v DeviceAuthorizationRequest) error
- func (t *PostTokenFormdataBody) FromDeviceTokenPollRequest(v DeviceTokenPollRequest) error
- func (t PostTokenFormdataBody) MarshalJSON() ([]byte, error)
- func (t *PostTokenFormdataBody) MergeDeviceAuthorizationRequest(v DeviceAuthorizationRequest) error
- func (t *PostTokenFormdataBody) MergeDeviceTokenPollRequest(v DeviceTokenPollRequest) error
- func (t *PostTokenFormdataBody) UnmarshalJSON(b []byte) error
- type PostTokenFormdataRequestBody
- type PostTokenParams
- type PostTokenResponse
- func (r PostTokenResponse) ContentType() string
- func (r PostTokenResponse) GetBody() []byte
- func (r PostTokenResponse) GetJSON4XX() *OAuth2ErrorResponse
- func (r PostTokenResponse) GetJSON200() *PostToken200JSONResponseBody
- func (r PostTokenResponse) Status() string
- func (r PostTokenResponse) StatusCode() int
- type RefreshTokenRequest
- type RefreshTokenRequestGrantType
- type RequestEditorFn
- type TokenExpiry
Constants ¶
This section is empty.
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 constructs an http.Request for the PostOAuth2TokenRefresh method, with any body, and a specified content type
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 constructs an http.Request for the PostToken method, with any body, and a specified content type
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 Example: Bearer
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 (c *Client) PostOAuth2TokenRefreshWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
PostOAuth2TokenRefreshWithBody Refresh access token (Cognito OAuth 2 token endpoint)
Exchanges a **refresh token** for new **access** (and optionally **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
Request is **`application/x-www-form-urlencoded`** with `grant_type=refresh_token`, the public `client_id`, and the `refresh_token` value. Unlike the device-flow calls, parameters are sent in the **body only** (no duplicate query string in the current client).
Optional **HTTP Basic** authentication with `base64(client_id + ":" + client_secret)` when a client secret is configured (the bundled CLI client uses an empty secret).
Takes any type of body and a specified content type.
Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
func (*Client) PostOAuth2TokenRefreshWithFormdataBody ¶
func (c *Client) PostOAuth2TokenRefreshWithFormdataBody(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
PostOAuth2TokenRefreshWithFormdataBody Refresh access token (Cognito OAuth 2 token endpoint)
Exchanges a **refresh token** for new **access** (and optionally **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
Request is **`application/x-www-form-urlencoded`** with `grant_type=refresh_token`, the public `client_id`, and the `refresh_token` value. Unlike the device-flow calls, parameters are sent in the **body only** (no duplicate query string in the current client).
Optional **HTTP Basic** authentication with `base64(client_id + ":" + client_secret)` when a client secret is configured (the bundled CLI client uses an empty secret).
Takes a body of the `application/x-www-form-urlencoded` content type.
Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
func (*Client) PostTokenWithBody ¶
func (c *Client) PostTokenWithBody(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
PostTokenWithBody Device flow token endpoint (request codes or exchange device code)
**Step A — device authorization:** POST with only `client_id` to obtain `device_code`, `user_code`, and verification URIs.
**Step B — token:** POST with `client_id`, `device_code`, and `grant_type` set to the device code grant to poll until the user completes authorization or the code expires.
On step B, a `200` response carries access (and optionally refresh) tokens. Non-success responses while polling often return HTTP 400 (or similar) with a JSON body where `error` may be `authorization_pending` or `slow_down` (client should wait and retry).
Takes any type of body and a specified content type.
Corresponds with POST /token (the `PostToken` operationId).
func (*Client) PostTokenWithFormdataBody ¶
func (c *Client) PostTokenWithFormdataBody(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
PostTokenWithFormdataBody Device flow token endpoint (request codes or exchange device code)
**Step A — device authorization:** POST with only `client_id` to obtain `device_code`, `user_code`, and verification URIs.
**Step B — token:** POST with `client_id`, `device_code`, and `grant_type` set to the device code grant to poll until the user completes authorization or the code expires.
On step B, a `200` response carries access (and optionally refresh) tokens. Non-success responses while polling often return HTTP 400 (or similar) with a JSON body where `error` may be `authorization_pending` or `slow_down` (client should wait and retry).
Takes a body of the `application/x-www-form-urlencoded` content type.
Corresponds with POST /token (the `PostToken` operationId).
type ClientInterface ¶
type ClientInterface interface {
// PostOAuth2TokenRefreshWithBody Refresh access token (Cognito OAuth 2 token endpoint)
//
// Exchanges a **refresh token** for new **access** (and optionally
// **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
//
// Request is **`application/x-www-form-urlencoded`** with
// `grant_type=refresh_token`, the public `client_id`, and the
// `refresh_token` value. Unlike the device-flow calls, parameters are sent
// in the **body only** (no duplicate query string in the current client).
//
// Optional **HTTP Basic** authentication with
// `base64(client_id + ":" + client_secret)` when a client secret is
// configured (the bundled CLI client uses an empty secret).
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
PostOAuth2TokenRefreshWithBody(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// PostOAuth2TokenRefreshWithFormdataBody Refresh access token (Cognito OAuth 2 token endpoint)
//
// Exchanges a **refresh token** for new **access** (and optionally
// **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
//
// Request is **`application/x-www-form-urlencoded`** with
// `grant_type=refresh_token`, the public `client_id`, and the
// `refresh_token` value. Unlike the device-flow calls, parameters are sent
// in the **body only** (no duplicate query string in the current client).
//
// Optional **HTTP Basic** authentication with
// `base64(client_id + ":" + client_secret)` when a client secret is
// configured (the bundled CLI client uses an empty secret).
//
// Takes a body of the `application/x-www-form-urlencoded` content type.
//
// Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
PostOAuth2TokenRefreshWithFormdataBody(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*http.Response, error)
// PostTokenWithBody Device flow token endpoint (request codes or exchange device code)
//
// **Step A — device authorization:** POST with only `client_id` to obtain
// `device_code`, `user_code`, and verification URIs.
//
// **Step B — token:** POST with `client_id`, `device_code`, and
// `grant_type` set to the device code grant to poll until the user
// completes authorization or the code expires.
//
// On step B, a `200` response carries access (and optionally refresh)
// tokens. Non-success responses while polling often return HTTP 400 (or
// similar) with a JSON body where `error` may be `authorization_pending`
// or `slow_down` (client should wait and retry).
//
// Takes any type of body and a specified content type.
//
// Corresponds with POST /token (the `PostToken` operationId).
PostTokenWithBody(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*http.Response, error)
// PostTokenWithFormdataBody Device flow token endpoint (request codes or exchange device code)
//
// **Step A — device authorization:** POST with only `client_id` to obtain
// `device_code`, `user_code`, and verification URIs.
//
// **Step B — token:** POST with `client_id`, `device_code`, and
// `grant_type` set to the device code grant to poll until the user
// completes authorization or the code expires.
//
// On step B, a `200` response carries access (and optionally refresh)
// tokens. Non-success responses while polling often return HTTP 400 (or
// similar) with a JSON body where `error` may be `authorization_pending`
// or `slow_down` (client should wait and retry).
//
// Takes a body of the `application/x-www-form-urlencoded` content type.
//
// Corresponds with POST /token (the `PostToken` operationId).
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 Refresh access token (Cognito OAuth 2 token endpoint)
Exchanges a **refresh token** for new **access** (and optionally **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
Request is **`application/x-www-form-urlencoded`** with `grant_type=refresh_token`, the public `client_id`, and the `refresh_token` value. Unlike the device-flow calls, parameters are sent in the **body only** (no duplicate query string in the current client).
Optional **HTTP Basic** authentication with `base64(client_id + ":" + client_secret)` when a client secret is configured (the bundled CLI client uses an empty secret).
Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
func (*ClientWithResponses) PostOAuth2TokenRefreshWithFormdataBodyWithResponse ¶
func (c *ClientWithResponses) PostOAuth2TokenRefreshWithFormdataBodyWithResponse(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
PostOAuth2TokenRefreshWithFormdataBodyWithResponse Refresh access token (Cognito OAuth 2 token endpoint)
Exchanges a **refresh token** for new **access** (and optionally **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
Request is **`application/x-www-form-urlencoded`** with `grant_type=refresh_token`, the public `client_id`, and the `refresh_token` value. Unlike the device-flow calls, parameters are sent in the **body only** (no duplicate query string in the current client).
Optional **HTTP Basic** authentication with `base64(client_id + ":" + client_secret)` when a client secret is configured (the bundled CLI client uses an empty secret).
Takes a body of the `application/x-www-form-urlencoded` content type, and returns a wrapper object for the known response body format(s).
Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
func (*ClientWithResponses) PostTokenWithBodyWithResponse ¶
func (c *ClientWithResponses) PostTokenWithBodyWithResponse(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
PostTokenWithBodyWithResponse Device flow token endpoint (request codes or exchange device code)
**Step A — device authorization:** POST with only `client_id` to obtain `device_code`, `user_code`, and verification URIs.
**Step B — token:** POST with `client_id`, `device_code`, and `grant_type` set to the device code grant to poll until the user completes authorization or the code expires.
On step B, a `200` response carries access (and optionally refresh) tokens. Non-success responses while polling often return HTTP 400 (or similar) with a JSON body where `error` may be `authorization_pending` or `slow_down` (client should wait and retry).
Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
Corresponds with POST /token (the `PostToken` operationId).
func (*ClientWithResponses) PostTokenWithFormdataBodyWithResponse ¶
func (c *ClientWithResponses) PostTokenWithFormdataBodyWithResponse(ctx context.Context, params *PostTokenParams, body PostTokenFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
PostTokenWithFormdataBodyWithResponse Device flow token endpoint (request codes or exchange device code)
**Step A — device authorization:** POST with only `client_id` to obtain `device_code`, `user_code`, and verification URIs.
**Step B — token:** POST with `client_id`, `device_code`, and `grant_type` set to the device code grant to poll until the user completes authorization or the code expires.
On step B, a `200` response carries access (and optionally refresh) tokens. Non-success responses while polling often return HTTP 400 (or similar) with a JSON body where `error` may be `authorization_pending` or `slow_down` (client should wait and retry).
Takes a body of the `application/x-www-form-urlencoded` content type, and returns a wrapper object for the known response body format(s).
Corresponds with POST /token (the `PostToken` operationId).
type ClientWithResponsesInterface ¶
type ClientWithResponsesInterface interface {
// PostOAuth2TokenRefreshWithBodyWithResponse Refresh access token (Cognito OAuth 2 token endpoint)
//
// Exchanges a **refresh token** for new **access** (and optionally
// **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
//
// Request is **`application/x-www-form-urlencoded`** with
// `grant_type=refresh_token`, the public `client_id`, and the
// `refresh_token` value. Unlike the device-flow calls, parameters are sent
// in the **body only** (no duplicate query string in the current client).
//
// Optional **HTTP Basic** authentication with
// `base64(client_id + ":" + client_secret)` when a client secret is
// configured (the bundled CLI client uses an empty secret).
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
PostOAuth2TokenRefreshWithBodyWithResponse(ctx context.Context, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
// PostOAuth2TokenRefreshWithFormdataBodyWithResponse Refresh access token (Cognito OAuth 2 token endpoint)
//
// Exchanges a **refresh token** for new **access** (and optionally
// **refresh**) tokens. Used by `CredentialsService.RefreshTokens`.
//
// Request is **`application/x-www-form-urlencoded`** with
// `grant_type=refresh_token`, the public `client_id`, and the
// `refresh_token` value. Unlike the device-flow calls, parameters are sent
// in the **body only** (no duplicate query string in the current client).
//
// Optional **HTTP Basic** authentication with
// `base64(client_id + ":" + client_secret)` when a client secret is
// configured (the bundled CLI client uses an empty secret).
//
// Takes a body of the `application/x-www-form-urlencoded` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /oauth2/token (the `PostOAuth2TokenRefresh` operationId).
PostOAuth2TokenRefreshWithFormdataBodyWithResponse(ctx context.Context, body PostOAuth2TokenRefreshFormdataRequestBody, reqEditors ...RequestEditorFn) (*PostOAuth2TokenRefreshResponse, error)
// PostTokenWithBodyWithResponse Device flow token endpoint (request codes or exchange device code)
//
// **Step A — device authorization:** POST with only `client_id` to obtain
// `device_code`, `user_code`, and verification URIs.
//
// **Step B — token:** POST with `client_id`, `device_code`, and
// `grant_type` set to the device code grant to poll until the user
// completes authorization or the code expires.
//
// On step B, a `200` response carries access (and optionally refresh)
// tokens. Non-success responses while polling often return HTTP 400 (or
// similar) with a JSON body where `error` may be `authorization_pending`
// or `slow_down` (client should wait and retry).
//
// Takes any type of body and a specified content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /token (the `PostToken` operationId).
PostTokenWithBodyWithResponse(ctx context.Context, params *PostTokenParams, contentType string, body io.Reader, reqEditors ...RequestEditorFn) (*PostTokenResponse, error)
// PostTokenWithFormdataBodyWithResponse Device flow token endpoint (request codes or exchange device code)
//
// **Step A — device authorization:** POST with only `client_id` to obtain
// `device_code`, `user_code`, and verification URIs.
//
// **Step B — token:** POST with `client_id`, `device_code`, and
// `grant_type` set to the device code grant to poll until the user
// completes authorization or the code expires.
//
// On step B, a `200` response carries access (and optionally refresh)
// tokens. Non-success responses while polling often return HTTP 400 (or
// similar) with a JSON body where `error` may be `authorization_pending`
// or `slow_down` (client should wait and retry).
//
// Takes a body of the `application/x-www-form-urlencoded` content type, and returns a wrapper object for the known response body format(s).
//
// Corresponds with POST /token (the `PostToken` operationId).
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 the response for an HTTP 200 `application/json` response
JSON200 *AccessTokenResponse
// JSONDefault the response for an HTTP default `application/json` response
JSONDefault *OAuth2ErrorResponse
}
func ParsePostOAuth2TokenRefreshResponse ¶
func ParsePostOAuth2TokenRefreshResponse(rsp *http.Response) (*PostOAuth2TokenRefreshResponse, error)
ParsePostOAuth2TokenRefreshResponse parses an HTTP response from a PostOAuth2TokenRefreshWithResponse call
func (PostOAuth2TokenRefreshResponse) ContentType ¶ added in v0.0.2
func (r PostOAuth2TokenRefreshResponse) ContentType() string
ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (PostOAuth2TokenRefreshResponse) GetBody ¶ added in v0.0.2
func (r PostOAuth2TokenRefreshResponse) GetBody() []byte
GetBody returns the raw response body bytes
func (PostOAuth2TokenRefreshResponse) GetJSON200 ¶ added in v0.0.2
func (r PostOAuth2TokenRefreshResponse) GetJSON200() *AccessTokenResponse
GetJSON200 returns the response for an HTTP 200 `application/json` response
func (PostOAuth2TokenRefreshResponse) GetJSONDefault ¶ added in v0.0.2
func (r PostOAuth2TokenRefreshResponse) GetJSONDefault() *OAuth2ErrorResponse
GetJSONDefault returns the response for an HTTP default `application/json` response
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 PostToken200JSONResponseBody ¶ added in v0.0.2
type PostToken200JSONResponseBody struct {
// contains filtered or unexported fields
}
PostToken200JSONResponseBody defines parameters for PostToken.
func (PostToken200JSONResponseBody) AsAccessTokenResponse ¶ added in v0.0.2
func (t PostToken200JSONResponseBody) AsAccessTokenResponse() (AccessTokenResponse, error)
AsAccessTokenResponse returns the union data inside the PostToken200JSONResponseBody as a AccessTokenResponse
func (PostToken200JSONResponseBody) AsDeviceAuthorizationResponse ¶ added in v0.0.2
func (t PostToken200JSONResponseBody) AsDeviceAuthorizationResponse() (DeviceAuthorizationResponse, error)
AsDeviceAuthorizationResponse returns the union data inside the PostToken200JSONResponseBody as a DeviceAuthorizationResponse
func (*PostToken200JSONResponseBody) FromAccessTokenResponse ¶ added in v0.0.2
func (t *PostToken200JSONResponseBody) FromAccessTokenResponse(v AccessTokenResponse) error
FromAccessTokenResponse overwrites any union data inside the PostToken200JSONResponseBody as the provided AccessTokenResponse
func (*PostToken200JSONResponseBody) FromDeviceAuthorizationResponse ¶ added in v0.0.2
func (t *PostToken200JSONResponseBody) FromDeviceAuthorizationResponse(v DeviceAuthorizationResponse) error
FromDeviceAuthorizationResponse overwrites any union data inside the PostToken200JSONResponseBody as the provided DeviceAuthorizationResponse
func (PostToken200JSONResponseBody) MarshalJSON ¶ added in v0.0.2
func (t PostToken200JSONResponseBody) MarshalJSON() ([]byte, error)
func (*PostToken200JSONResponseBody) MergeAccessTokenResponse ¶ added in v0.0.2
func (t *PostToken200JSONResponseBody) MergeAccessTokenResponse(v AccessTokenResponse) error
MergeAccessTokenResponse performs a merge with any union data inside the PostToken200JSONResponseBody, using the provided AccessTokenResponse
func (*PostToken200JSONResponseBody) MergeDeviceAuthorizationResponse ¶ added in v0.0.2
func (t *PostToken200JSONResponseBody) MergeDeviceAuthorizationResponse(v DeviceAuthorizationResponse) error
MergeDeviceAuthorizationResponse performs a merge with any union data inside the PostToken200JSONResponseBody, using the provided DeviceAuthorizationResponse
func (*PostToken200JSONResponseBody) UnmarshalJSON ¶ added in v0.0.2
func (t *PostToken200JSONResponseBody) UnmarshalJSON(b []byte) error
type PostTokenFormdataBody ¶
type PostTokenFormdataBody struct {
// contains filtered or unexported fields
}
PostTokenFormdataBody defines parameters for PostToken.
func (PostTokenFormdataBody) AsDeviceAuthorizationRequest ¶ added in v0.0.2
func (t PostTokenFormdataBody) AsDeviceAuthorizationRequest() (DeviceAuthorizationRequest, error)
AsDeviceAuthorizationRequest returns the union data inside the PostTokenFormdataBody as a DeviceAuthorizationRequest
func (PostTokenFormdataBody) AsDeviceTokenPollRequest ¶ added in v0.0.2
func (t PostTokenFormdataBody) AsDeviceTokenPollRequest() (DeviceTokenPollRequest, error)
AsDeviceTokenPollRequest returns the union data inside the PostTokenFormdataBody as a DeviceTokenPollRequest
func (*PostTokenFormdataBody) FromDeviceAuthorizationRequest ¶ added in v0.0.2
func (t *PostTokenFormdataBody) FromDeviceAuthorizationRequest(v DeviceAuthorizationRequest) error
FromDeviceAuthorizationRequest overwrites any union data inside the PostTokenFormdataBody as the provided DeviceAuthorizationRequest
func (*PostTokenFormdataBody) FromDeviceTokenPollRequest ¶ added in v0.0.2
func (t *PostTokenFormdataBody) FromDeviceTokenPollRequest(v DeviceTokenPollRequest) error
FromDeviceTokenPollRequest overwrites any union data inside the PostTokenFormdataBody as the provided DeviceTokenPollRequest
func (PostTokenFormdataBody) MarshalJSON ¶ added in v0.0.2
func (t PostTokenFormdataBody) MarshalJSON() ([]byte, error)
func (*PostTokenFormdataBody) MergeDeviceAuthorizationRequest ¶ added in v0.0.2
func (t *PostTokenFormdataBody) MergeDeviceAuthorizationRequest(v DeviceAuthorizationRequest) error
MergeDeviceAuthorizationRequest performs a merge with any union data inside the PostTokenFormdataBody, using the provided DeviceAuthorizationRequest
func (*PostTokenFormdataBody) MergeDeviceTokenPollRequest ¶ added in v0.0.2
func (t *PostTokenFormdataBody) MergeDeviceTokenPollRequest(v DeviceTokenPollRequest) error
MergeDeviceTokenPollRequest performs a merge with any union data inside the PostTokenFormdataBody, using the provided DeviceTokenPollRequest
func (*PostTokenFormdataBody) UnmarshalJSON ¶ added in v0.0.2
func (t *PostTokenFormdataBody) UnmarshalJSON(b []byte) error
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 the response for an HTTP 200 `application/json` response
JSON200 *PostToken200JSONResponseBody
// JSON4XX the response for an HTTP 4XX `application/json` response
JSON4XX *OAuth2ErrorResponse
}
func ParsePostTokenResponse ¶
func ParsePostTokenResponse(rsp *http.Response) (*PostTokenResponse, error)
ParsePostTokenResponse parses an HTTP response from a PostTokenWithResponse call
func (PostTokenResponse) ContentType ¶ added in v0.0.2
func (r PostTokenResponse) ContentType() string
ContentType is a convenience method to retrieve the Content-Type value from the HTTP response headers
func (PostTokenResponse) GetBody ¶ added in v0.0.2
func (r PostTokenResponse) GetBody() []byte
GetBody returns the raw response body bytes
func (PostTokenResponse) GetJSON4XX ¶ added in v0.0.2
func (r PostTokenResponse) GetJSON4XX() *OAuth2ErrorResponse
GetJSON4XX returns the response for an HTTP 4XX `application/json` response
func (PostTokenResponse) GetJSON200 ¶ added in v0.0.2
func (r PostTokenResponse) GetJSON200() *PostToken200JSONResponseBody
GetJSON200 returns the response for an HTTP 200 `application/json` response
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.
func (RefreshTokenRequestGrantType) Valid ¶ added in v0.0.2
func (e RefreshTokenRequestGrantType) Valid() bool
Valid indicates whether the value is a known member of the RefreshTokenRequestGrantType enum.
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.