Use OIDC config for retrieving user information (#3006)
Also extracts a request.NewClient method
This commit is contained in:
parent
4a921e3825
commit
10449032ac
13 changed files with 55 additions and 88 deletions
|
|
@ -118,7 +118,7 @@ func teslaToken() (*oauth2.Token, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewHelper(log).Client)
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewClient(log))
|
||||
client, err := tesla.NewClient(
|
||||
ctx,
|
||||
tesla.WithMFAHandler(codePrompt),
|
||||
|
|
|
|||
9
go.mod
9
go.mod
|
|
@ -17,7 +17,7 @@ require (
|
|||
github.com/cjrd/allocate v0.0.0-20191115010018-022b87fe59fc
|
||||
github.com/cloudfoundry/jibber_jabber v0.0.0-20151120183258-bcc4c8345a21
|
||||
github.com/containrrr/shoutrrr v0.5.2
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible
|
||||
github.com/coreos/go-oidc/v3 v3.1.1-0.20220324025715-2d47dd951527
|
||||
github.com/denisbrodbeck/machineid v1.0.1
|
||||
github.com/dustin/go-humanize v1.0.0
|
||||
github.com/dylanmei/iso8601 v0.1.0
|
||||
|
|
@ -74,12 +74,12 @@ require (
|
|||
github.com/volkszaehler/mbmd v0.0.0-20220208145932-d2d3cba909f5
|
||||
github.com/writeas/go-strip-markdown v2.0.1+incompatible
|
||||
gitlab.com/bboehmke/sunny v0.15.1-0.20211022160056-2fba1c86ade6
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f
|
||||
golang.org/x/net v0.0.0-20220325170049-de3da57026de
|
||||
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
|
||||
golang.org/x/text v0.3.7
|
||||
google.golang.org/api v0.73.0
|
||||
google.golang.org/grpc v1.45.0
|
||||
google.golang.org/protobuf v1.27.1
|
||||
google.golang.org/protobuf v1.28.0
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
|
||||
)
|
||||
|
||||
|
|
@ -134,7 +134,6 @@ require (
|
|||
github.com/pelletier/go-toml/v2 v2.0.0-beta.6 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/pquerna/cachecontrol v0.1.0 // indirect
|
||||
github.com/prometheus/client_model v0.2.0 // indirect
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
|
|
@ -149,7 +148,7 @@ require (
|
|||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
go.opencensus.io v0.23.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 // indirect
|
||||
golang.org/x/mod v0.5.1 // indirect
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
||||
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
|
||||
|
|
|
|||
18
go.sum
18
go.sum
|
|
@ -162,8 +162,8 @@ github.com/containrrr/shoutrrr v0.5.2/go.mod h1:XSU8tOIZ1JG8m6OuPozfGLpj6Ed+S8Zr
|
|||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible h1:mh48q/BqXqgjVHpy2ZY7WnWAbenxRjsz9N1i1YxjHAk=
|
||||
github.com/coreos/go-oidc v2.2.1+incompatible/go.mod h1:CgnwVTmzoESiwO9qyAFEMiHoZ1nMCKZlZ9V6mm3/LKc=
|
||||
github.com/coreos/go-oidc/v3 v3.1.1-0.20220324025715-2d47dd951527 h1:hK/MZLOLhRU3q4j5l9j+mgNgfUDJJiqLqUcJD7LVaQg=
|
||||
github.com/coreos/go-oidc/v3 v3.1.1-0.20220324025715-2d47dd951527/go.mod h1:rEJ/idjfUyfkBit1eI1fvyr+64/g9dcKpAm8MJMesvo=
|
||||
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
|
|
@ -677,8 +677,6 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb
|
|||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/posener/complete v1.2.3/go.mod h1:WZIdtGGp+qx0sLrYKtIRAruyNpv6hFCicSgv7Sy7s/s=
|
||||
github.com/pquerna/cachecontrol v0.1.0 h1:yJMy84ti9h/+OEWa752kBTKv4XC30OtVVHYv/8cTqKc=
|
||||
github.com/pquerna/cachecontrol v0.1.0/go.mod h1:NrUG3Z7Rdu85UNR3vm7SOsl1nFIeSiQnrHV5K9mBcUI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||
|
|
@ -871,8 +869,8 @@ golang.org/x/crypto v0.0.0-20210711020723-a769d52b0f97/go.mod h1:GvvjBRRGRdwPK5y
|
|||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292 h1:f+lwQ+GtmgoY+A2YaQxlSOnDjXcQ7ZRLWOHbC6HtRqE=
|
||||
golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
|
||||
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
|
|
@ -943,6 +941,7 @@ golang.org/x/net v0.0.0-20200301022130-244492dfa37a/go.mod h1:z5CRVTTTmAJ677TzLL
|
|||
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200425230154-ff2c4b7c35a0/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200505041828-1ed23360d12c/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
|
|
@ -975,8 +974,9 @@ golang.org/x/net v0.0.0-20211111160137-58aab5ef257a/go.mod h1:9nx3DQGgdP8bBQD5qx
|
|||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
|
||||
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/net v0.0.0-20220325170049-de3da57026de h1:pZB1TWnKi+o4bENlbzAgLrEbY4RMYmUIRobMcSmfeYc=
|
||||
golang.org/x/net v0.0.0-20220325170049-de3da57026de/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
|
|
@ -1362,8 +1362,9 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
|
|||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.27.1 h1:SnqbnDw1V7RiZcXPx5MEeqPv2s79L9i7BJUlG/+RurQ=
|
||||
google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
google.golang.org/protobuf v1.28.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
|
||||
gopkg.in/airbrake/gobrake.v2 v2.0.9/go.mod h1:/h5ZAUhDkGaJfjzjKLSjv6zCL6O0LLBxU4K+aSYdM/U=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
|
@ -1389,6 +1390,7 @@ gopkg.in/readline.v1 v1.0.0-20160726135117-62c6fe619375/go.mod h1:lNEQeAhU009zbR
|
|||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/sourcemap.v1 v1.0.5 h1:inv58fC9f9J3TK2Y2R1NPntXEn3/wjWHkonhIUODNTI=
|
||||
gopkg.in/sourcemap.v1 v1.0.5/go.mod h1:2RlvNNSMglmRrcvhfuzp4hQHwOtjxlbjX7UPY/GXb78=
|
||||
gopkg.in/square/go-jose.v2 v2.5.1/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
||||
gopkg.in/square/go-jose.v2 v2.6.0 h1:NGk74WTnPKBNUhNzQX7PYcTLUjoq7mzKk2OKbvwk2iI=
|
||||
gopkg.in/square/go-jose.v2 v2.6.0/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
|
|
|
|||
|
|
@ -17,16 +17,19 @@ type Helper struct {
|
|||
*http.Client
|
||||
}
|
||||
|
||||
// NewClient creates http client with default transport
|
||||
func NewClient(log *util.Logger) *http.Client {
|
||||
return &http.Client{
|
||||
Timeout: Timeout,
|
||||
Transport: NewTripper(log, transport.Default()),
|
||||
}
|
||||
}
|
||||
|
||||
// NewHelper creates http helper for simplified PUT GET logic
|
||||
func NewHelper(log *util.Logger) *Helper {
|
||||
r := &Helper{
|
||||
Client: &http.Client{
|
||||
Timeout: Timeout,
|
||||
Transport: NewTripper(log, transport.Default()),
|
||||
},
|
||||
return &Helper{
|
||||
Client: NewClient(log),
|
||||
}
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
// DoBody executes HTTP request and returns the response body
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import (
|
|||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/vehicle/audi/etron"
|
||||
"github.com/evcc-io/evcc/vehicle/id"
|
||||
"github.com/evcc-io/evcc/vehicle/vag"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/idkproxy"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/service"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/vwidentity"
|
||||
|
|
@ -68,7 +67,7 @@ func NewEtronFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
cc.VIN, err = ensureVehicle(cc.VIN, api.Vehicles)
|
||||
|
||||
if err == nil {
|
||||
api := id.NewAPI(log, vag.IDTokenSource(its))
|
||||
api := id.NewAPI(log, its)
|
||||
api.Client.Timeout = cc.Timeout
|
||||
|
||||
v.Provider = id.NewProvider(api, cc.VIN, cc.Cache)
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func NewAPI(log *util.Logger, ts oauth2.TokenSource) *API {
|
|||
ctx := context.WithValue(
|
||||
context.Background(),
|
||||
oauth2.HTTPClient,
|
||||
request.NewHelper(log).Client,
|
||||
request.NewClient(log),
|
||||
)
|
||||
|
||||
v := &API{
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/coreos/go-oidc"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/evcc-io/evcc/api"
|
||||
"github.com/evcc-io/evcc/provider"
|
||||
"github.com/evcc-io/evcc/server/auth"
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
package vehicle
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/evcc-io/evcc/api"
|
||||
|
|
@ -10,6 +12,7 @@ import (
|
|||
"github.com/evcc-io/evcc/vehicle/seat"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/tokenrefreshservice"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/vwidentity"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// Cupra is an api.Vehicle implementation for Seat Cupra cars
|
||||
|
|
@ -56,12 +59,16 @@ func NewCupraFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
return nil, err
|
||||
}
|
||||
|
||||
ui, err := vwidentity.UserInfo(log, token)
|
||||
ts := trs.TokenSource(token)
|
||||
|
||||
// get OIDC user information
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewClient(log))
|
||||
ui, err := vwidentity.Config.NewProvider(ctx).UserInfo(ctx, ts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, fmt.Errorf("failed getting user information: %w", err)
|
||||
}
|
||||
|
||||
api := cupra.NewAPI(log, trs.TokenSource(token))
|
||||
api := cupra.NewAPI(log, ts)
|
||||
|
||||
cc.VIN, err = ensureVehicle(cc.VIN, func() ([]string, error) {
|
||||
return api.Vehicles(ui.Subject)
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func NewTeslaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
|
||||
// authenticated http client with logging injected to the Tesla client
|
||||
log := util.NewLogger("tesla").Redact(cc.Tokens.Access, cc.Tokens.Refresh)
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewHelper(log).Client)
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewClient(log))
|
||||
|
||||
options := []tesla.ClientOption{tesla.WithToken(&oauth2.Token{
|
||||
AccessToken: cc.Tokens.Access,
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ func NewTronityFromConfig(other map[string]interface{}) (api.Vehicle, error) {
|
|||
ts = oauth.RefreshTokenSource(&oauth2.Token{}, v)
|
||||
} else {
|
||||
// use provided tokens generated by code flow
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewHelper(log).Client)
|
||||
ctx := context.WithValue(context.Background(), oauth2.HTTPClient, request.NewClient(log))
|
||||
ts = oc.TokenSource(ctx, &oauth2.Token{
|
||||
AccessToken: cc.Tokens.Access,
|
||||
RefreshToken: cc.Tokens.Refresh,
|
||||
|
|
|
|||
|
|
@ -10,22 +10,21 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/urlvalues"
|
||||
"github.com/evcc-io/evcc/vehicle/vag"
|
||||
"github.com/evcc-io/evcc/vehicle/vag/vwidentity"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
BaseURL = "https://idkproxy-service.apps.emea.vwapps.io"
|
||||
WellKnown = BaseURL + "/v1/emea/openid-configuration"
|
||||
WellKnown = "https://idkproxy-service.apps.emea.vwapps.io/v1/emea/openid-configuration"
|
||||
)
|
||||
|
||||
var Endpoint = &oauth2.Endpoint{
|
||||
AuthURL: vwidentity.Endpoint.AuthURL,
|
||||
TokenURL: BaseURL + "/v1/emea/token",
|
||||
var Config = &oidc.ProviderConfig{
|
||||
AuthURL: "https://identity.vwgroup.io/oidc/v1/authorize",
|
||||
TokenURL: "https://idkproxy-service.apps.emea.vwapps.io/v1/emea/token",
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
|
|
@ -71,7 +70,7 @@ func (v *Service) Exchange(q url.Values) (*vag.Token, error) {
|
|||
|
||||
var res vag.Token
|
||||
|
||||
req, err := request.New(http.MethodPost, Endpoint.TokenURL, strings.NewReader(data.Encode()), map[string]string{
|
||||
req, err := request.New(http.MethodPost, Config.TokenURL, strings.NewReader(data.Encode()), map[string]string{
|
||||
"Content-Type": request.FormContent,
|
||||
"Accept": request.JSONContent,
|
||||
"x-qmauth": qmauthNow(),
|
||||
|
|
@ -95,7 +94,7 @@ func (v *Service) Refresh(token *vag.Token) (*vag.Token, error) {
|
|||
|
||||
var res vag.Token
|
||||
|
||||
req, err := request.New(http.MethodPost, Endpoint.TokenURL, strings.NewReader(data.Encode()), map[string]string{
|
||||
req, err := request.New(http.MethodPost, Config.TokenURL, strings.NewReader(data.Encode()), map[string]string{
|
||||
"Content-Type": request.FormContent,
|
||||
"Accept": request.JSONContent,
|
||||
"x-qmauth": qmauthNow(),
|
||||
|
|
|
|||
|
|
@ -117,28 +117,3 @@ func (ts *metaTokenSource) TokenEx() (*Token, error) {
|
|||
|
||||
return token, err
|
||||
}
|
||||
|
||||
type idTokenSource struct {
|
||||
ts TokenSource
|
||||
}
|
||||
|
||||
// IDTokenSource provides an oauth2 token source with access_token populated from vag id_token
|
||||
func IDTokenSource(ts TokenSource) oauth2.TokenSource {
|
||||
return &idTokenSource{ts}
|
||||
}
|
||||
|
||||
// Token returns an oauth2 token or an error
|
||||
func (ts *idTokenSource) Token() (*oauth2.Token, error) {
|
||||
token, err := ts.ts.TokenEx()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
idToken := &oauth2.Token{
|
||||
TokenType: token.TokenType,
|
||||
AccessToken: token.IDToken,
|
||||
Expiry: token.Expiry,
|
||||
}
|
||||
|
||||
return idToken, err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,31 +8,29 @@ import (
|
|||
"net/url"
|
||||
"strings"
|
||||
|
||||
"github.com/coreos/go-oidc"
|
||||
"github.com/coreos/go-oidc/v3/oidc"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/evcc-io/evcc/util/request"
|
||||
"github.com/evcc-io/evcc/util/urlvalues"
|
||||
"github.com/evcc-io/evcc/vehicle/vag"
|
||||
"github.com/google/uuid"
|
||||
"golang.org/x/net/publicsuffix"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
const (
|
||||
BaseURL = "https://identity.vwgroup.io"
|
||||
WellKnown = "https://identity.vwgroup.io/.well-known/openid-configuration"
|
||||
UserInfoURL = "https://identity-userinfo.vwgroup.io/oidc/userinfo"
|
||||
BaseURL = "https://identity.vwgroup.io"
|
||||
WellKnown = "https://identity.vwgroup.io/.well-known/openid-configuration"
|
||||
)
|
||||
|
||||
// TODO use OIDC provider instead
|
||||
var Endpoint = &oauth2.Endpoint{
|
||||
AuthURL: BaseURL + "/oidc/v1/authorize",
|
||||
TokenURL: BaseURL + "/oidc/v1/token",
|
||||
var Config = &oidc.ProviderConfig{
|
||||
AuthURL: "https://identity.vwgroup.io/oidc/v1/authorize",
|
||||
TokenURL: "https://identity.vwgroup.io/oidc/v1/token",
|
||||
UserInfoURL: "https://identity-userinfo.vwgroup.io/oidc/userinfo",
|
||||
}
|
||||
|
||||
// Login performs VW identity login with optional code challenge
|
||||
func Login(log *util.Logger, q url.Values, user, password string) (url.Values, error) {
|
||||
return LoginWithAuthURL(log, Endpoint.AuthURL, q, user, password)
|
||||
return LoginWithAuthURL(log, Config.AuthURL, q, user, password)
|
||||
}
|
||||
func LoginWithAuthURL(log *util.Logger, uri string, q url.Values, user, password string) (url.Values, error) {
|
||||
var verify func(url.Values)
|
||||
|
|
@ -58,21 +56,6 @@ func LoginWithAuthURL(log *util.Logger, uri string, q url.Values, user, password
|
|||
return q, nil
|
||||
}
|
||||
|
||||
// UserInfo returns the OIDS user information
|
||||
func UserInfo(log *util.Logger, token *vag.Token) (oidc.UserInfo, error) {
|
||||
var ui oidc.UserInfo
|
||||
|
||||
req, err := request.New(http.MethodGet, UserInfoURL, nil, map[string]string{
|
||||
"Authorization": "Bearer " + token.AccessToken,
|
||||
"Accept": "application/json",
|
||||
})
|
||||
if err == nil {
|
||||
err = request.NewHelper(log).DoJSON(req, &ui)
|
||||
}
|
||||
|
||||
return ui, err
|
||||
}
|
||||
|
||||
type Service struct {
|
||||
*request.Helper
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue