oauth2

package
v0.0.0-...-37356b8 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2023 License: MIT, BSD-3-Clause Imports: 7 Imported by: 0

README

OAuth2 for Withings API

OAuth2 package extends golang.org/x/oauth2 to support using OAuth2 to access Withings.

License

Some of the code in this package has been copied from golang.org/x/oauth2 and is under a BSD-style license. See the License File for more information.

The rest of the code is under the MIT License. See the License File in the repository root for more information.

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

Constants

This section is empty.

Variables

View Source
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

View Source
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

View Source
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 Config

type Config = oauth2.Config

Config is an alias to oauth2.Config.

type WithingsConfig

type WithingsConfig struct {
	*oauth2.Config
}

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

func (c *WithingsConfig) Client(ctx context.Context, t *oauth2.Token) *http.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

func (c *WithingsConfig) Exchange(ctx context.Context, code string) (*oauth2.Token, error)

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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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