1
0
mirror of https://github.com/go-micro/go-micro.git synced 2025-03-03 15:22:30 +02:00
2021-01-20 21:01:10 +00:00

30 lines
681 B
Go

package eureka
import (
"context"
"net/http"
"github.com/asim/go-micro/v3/registry"
"golang.org/x/oauth2"
"golang.org/x/oauth2/clientcredentials"
)
type contextHttpClient struct{}
var newOAuthClient = func(c clientcredentials.Config) *http.Client {
return c.Client(oauth2.NoContext)
}
// Enable OAuth 2.0 Client Credentials Grant Flow
func OAuth2ClientCredentials(clientID, clientSecret, tokenURL string) registry.Option {
return func(o *registry.Options) {
c := clientcredentials.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: tokenURL,
}
o.Context = context.WithValue(o.Context, contextHttpClient{}, newOAuthClient(c))
}
}