mirror of
https://github.com/golang/oauth2.git
synced 2025-07-21 00:00:09 +08:00
client_secret should be optional.
This commit is contained in:
parent
cd4a6ded37
commit
32b8a902e6
22
oauth2.go
22
oauth2.go
@ -96,15 +96,14 @@ func NewConfig(opts *Options, authURL, tokenURL string) (*Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
conf := &Config{
|
if opts.ClientID == "" {
|
||||||
|
return nil, errors.New("oauth2: missing client ID")
|
||||||
|
}
|
||||||
|
return &Config{
|
||||||
opts: opts,
|
opts: opts,
|
||||||
authURL: aURL,
|
authURL: aURL,
|
||||||
tokenURL: tURL,
|
tokenURL: tURL,
|
||||||
}
|
}, nil
|
||||||
if err = conf.validate(); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return conf, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Config represents the configuration of an OAuth 2.0 consumer client.
|
// Config represents the configuration of an OAuth 2.0 consumer client.
|
||||||
@ -188,17 +187,6 @@ func (c *Config) FetchToken(existing *Token) (*Token, error) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checks if all required configuration fields have non-zero values.
|
|
||||||
func (c *Config) validate() error {
|
|
||||||
if c.opts.ClientID == "" {
|
|
||||||
return errors.New("oauth2: missing client ID")
|
|
||||||
}
|
|
||||||
if c.opts.ClientSecret == "" {
|
|
||||||
return errors.New("oauth2: missing client secret")
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exchange exchanges the authorization code with the OAuth 2.0 provider
|
// Exchange exchanges the authorization code with the OAuth 2.0 provider
|
||||||
// to retrieve a new access token.
|
// to retrieve a new access token.
|
||||||
func (c *Config) Exchange(code string) (*Token, error) {
|
func (c *Config) Exchange(code string) (*Token, error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user