Documentation ¶
Overview ¶
Package oauth2 extends "golang.org/x/oauth2" to support using OAuth2 to access Withings.
Notable deviations from standard OAuth2:
The "scope" parameter is comma separated, not space separated.
The token endpoint requires an additional "action" parameter to differentiate between authorization code exchange and token refresh.
The token response payload is wrapped in a custom response envelope applied to every API response. More details about this change: https://support.withings.com/hc/en-us/articles/360016745358--BREAKING-Deprecating-access-and-refresh-tokens-endpoints
Read more about the Withings OAuth2 API here: https://developer.withings.com/api-reference#tag/oauth2
Index ¶
- Variables
- type Config
- type WithingsConfig
- func (c *WithingsConfig) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
- func (c *WithingsConfig) Client(ctx context.Context, t *oauth2.Token) *http.Client
- func (c *WithingsConfig) Exchange(ctx context.Context, code string) (*oauth2.Token, error)
- func (c *WithingsConfig) TokenSource(ctx context.Context, t *oauth2.Token) oauth2.TokenSource
Constants ¶
This section is empty.
Variables ¶
var Endpoint = oauth2.Endpoint{ AuthURL: "https://account.withings.com/oauth2_user/authorize2", TokenURL: "https://wbsapi.withings.net/v2/oauth2", AuthStyle: oauth2.AuthStyleInParams, }
Endpoint is the Public Cloud endpoint for Withings.
https://developer.withings.com/developer-guide/v3/withings-solutions/app-to-app-solution
var EndpointHIPAA = oauth2.Endpoint{ AuthURL: "https://account.us.withingsmed.com/oauth2_user/authorize2", TokenURL: "https://wbsapi.us.withingsmed.net/v2/oauth2", AuthStyle: oauth2.AuthStyleInParams, }
Endpoint is the HIPAA endpoint for Withings.
https://developer.withings.com/developer-guide/v3/withings-solutions/security-and-compliance
var ModeDemo = oauth2.SetAuthURLParam("mode", "demo")
ModeDemo automatically logs the user in as a demo user.
https://developer.withings.com/developer-guide/data-api/demo-user#demo-user
Functions ¶
This section is empty.
Types ¶
type WithingsConfig ¶
WithingsConfig wraps a golang.org/x/oauth2.Config struct to extend its functionality with Withings specific behavior.
func (*WithingsConfig) AuthCodeURL ¶
func (c *WithingsConfig) AuthCodeURL(state string, opts ...oauth2.AuthCodeOption) string
AuthCodeURL returns a URL to OAuth 2.0 provider's consent page that asks for permissions for the required scopes explicitly.
It wraps the same function from golang.org/x/oauth2.Config and makes the scope parameter a comma separated string.
https://developer.withings.com/api-reference#operation/oauth2-authorize
func (*WithingsConfig) Client ¶
Client returns an HTTP client using the provided token. The token will auto-refresh as necessary. The underlying HTTP transport will be obtained using the provided context. The returned client and its Transport should not be modified.
func (*WithingsConfig) Exchange ¶
Exchange converts an authorization code into a token.
It reimplements parts of the same function from golang.org/x/oauth2.Config to make it compatible with the Withings API.
https://developer.withings.com/api-reference#operation/oauth2-getaccesstoken
func (*WithingsConfig) TokenSource ¶
func (c *WithingsConfig) TokenSource(ctx context.Context, t *oauth2.Token) oauth2.TokenSource
TokenSource returns a TokenSource that returns t until t expires, automatically refreshing it as necessary using the provided context.
Most users will use Config.Client instead.