Mercedes: update oauth2 config (#4742)
This commit is contained in:
parent
a35010edd9
commit
cc04229768
4 changed files with 21 additions and 10 deletions
|
|
@ -20,6 +20,7 @@ import (
|
||||||
|
|
||||||
// https://github.com/TA2k/ioBroker.smart-eq
|
// https://github.com/TA2k/ioBroker.smart-eq
|
||||||
|
|
||||||
|
// https://id.mercedes-benz.com/.well-known/openid-configuration
|
||||||
const OAuthURI = "https://id.mercedes-benz.com"
|
const OAuthURI = "https://id.mercedes-benz.com"
|
||||||
|
|
||||||
type Identity struct {
|
type Identity struct {
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,11 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
||||||
return nil, errors.New("missing credentials")
|
return nil, errors.New("missing credentials")
|
||||||
}
|
}
|
||||||
|
|
||||||
var options []mercedes.IdentityOptions
|
if cc.VIN == "" {
|
||||||
|
return nil, errors.New("missing vin")
|
||||||
|
}
|
||||||
|
|
||||||
|
var options []mercedes.IdentityOption
|
||||||
|
|
||||||
// TODO Load tokens from a persistence storage and use those during startup
|
// TODO Load tokens from a persistence storage and use those during startup
|
||||||
// e.g. persistence.Load("key")
|
// e.g. persistence.Load("key")
|
||||||
|
|
|
||||||
|
|
@ -15,10 +15,13 @@ import (
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
)
|
)
|
||||||
|
|
||||||
type IdentityOptions func(c *Identity) error
|
// https://ssoalpha.dvb.corpinter.net/v1/.well-known/openid-configuration
|
||||||
|
const OAuthURI = "https://ssoalpha.dvb.corpinter.net/v1"
|
||||||
|
|
||||||
|
type IdentityOption func(c *Identity) error
|
||||||
|
|
||||||
// WithToken provides an oauth2.Token to the client for auth.
|
// WithToken provides an oauth2.Token to the client for auth.
|
||||||
func WithToken(t *oauth2.Token) IdentityOptions {
|
func WithToken(t *oauth2.Token) IdentityOption {
|
||||||
return func(v *Identity) error {
|
return func(v *Identity) error {
|
||||||
v.ReuseTokenSource.Apply(t)
|
v.ReuseTokenSource.Apply(t)
|
||||||
return nil
|
return nil
|
||||||
|
|
@ -34,8 +37,8 @@ type Identity struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO SessionSecret from config/persistence
|
// TODO SessionSecret from config/persistence
|
||||||
func NewIdentity(log *util.Logger, id, secret string, options ...IdentityOptions) (*Identity, error) {
|
func NewIdentity(log *util.Logger, id, secret string, options ...IdentityOption) (*Identity, error) {
|
||||||
provider, err := oidc.NewProvider(context.Background(), "https://id.mercedes-benz.com")
|
provider, err := oidc.NewProvider(context.Background(), OAuthURI)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to initialize OIDC provider: %s", err)
|
return nil, fmt.Errorf("failed to initialize OIDC provider: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +47,11 @@ func NewIdentity(log *util.Logger, id, secret string, options ...IdentityOptions
|
||||||
ClientID: id,
|
ClientID: id,
|
||||||
ClientSecret: secret,
|
ClientSecret: secret,
|
||||||
Endpoint: provider.Endpoint(),
|
Endpoint: provider.Endpoint(),
|
||||||
Scopes: []string{oidc.ScopeOfflineAccess, "mb:vehicle:mbdata:evstatus"},
|
Scopes: []string{
|
||||||
|
oidc.ScopeOpenID,
|
||||||
|
oidc.ScopeOfflineAccess,
|
||||||
|
"mb:vehicle:mbdata:evstatus",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
v := &Identity{
|
v := &Identity{
|
||||||
|
|
@ -61,12 +68,12 @@ func NewIdentity(log *util.Logger, id, secret string, options ...IdentityOptions
|
||||||
v.ReuseTokenSource = ts
|
v.ReuseTokenSource = ts
|
||||||
|
|
||||||
for _, o := range options {
|
for _, o := range options {
|
||||||
if err == nil {
|
if err := o(v); err != nil {
|
||||||
err = o(v)
|
return v, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return v, err
|
return v, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// invalidToken is the callback for the token source when token expires
|
// invalidToken is the callback for the token source when token expires
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,6 @@ import (
|
||||||
|
|
||||||
const ApiURI = "https://oneapp.microservice.smart.com/seqc/v0"
|
const ApiURI = "https://oneapp.microservice.smart.com/seqc/v0"
|
||||||
|
|
||||||
// https://id.mercedes-benz.com/.well-known/openid-configuration
|
|
||||||
var OAuth2Config = &oauth2.Config{
|
var OAuth2Config = &oauth2.Config{
|
||||||
ClientID: "70d89501-938c-4bec-82d0-6abb550b0825",
|
ClientID: "70d89501-938c-4bec-82d0-6abb550b0825",
|
||||||
RedirectURL: "https://oneapp.microservice.smart.com",
|
RedirectURL: "https://oneapp.microservice.smart.com",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue