Skip to content

Commit

Permalink
add client_id to support Microsoft Entra ID in int128/kubelogin
Browse files Browse the repository at this point in the history
  • Loading branch information
markush81 authored and peick committed Jan 5, 2025
1 parent 49a531d commit 91c299a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ func (c *Config) Exchange(ctx context.Context, code string, opts ...AuthCodeOpti
v := url.Values{
"grant_type": {"authorization_code"},
"code": {code},
"client_id": {c.ClientID},
}
if c.RedirectURL != "" {
v.Set("redirect_uri", c.RedirectURL)
Expand Down Expand Up @@ -280,6 +281,7 @@ func (tf *tokenRefresher) Token() (*Token, error) {
tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{
"grant_type": {"refresh_token"},
"refresh_token": {tf.refreshToken},
"client_id": {tf.conf.ClientID},
})

if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func TestExchangeRequest(t *testing.T) {
if err != nil {
t.Errorf("Failed reading request body: %s.", err)
}
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
t.Errorf("Unexpected exchange payload; got %q", body)
}
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
Expand Down Expand Up @@ -152,7 +152,7 @@ func TestExchangeRequest_CustomParam(t *testing.T) {
if err != nil {
t.Errorf("Failed reading request body: %s.", err)
}
if string(body) != "code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
if string(body) != "client_id=CLIENT_ID&code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
}
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestExchangeRequest_JSONResponse(t *testing.T) {
if err != nil {
t.Errorf("Failed reading request body: %s.", err)
}
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
}
w.Header().Set("Content-Type", "application/json")
Expand Down Expand Up @@ -436,7 +436,7 @@ func TestTokenRefreshRequest(t *testing.T) {
t.Errorf("Unexpected Content-Type header %q", headerContentType)
}
body, _ := ioutil.ReadAll(r.Body)
if string(body) != "grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
if string(body) != "client_id=CLIENT_ID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
t.Errorf("Unexpected refresh token payload %q", body)
}
w.Header().Set("Content-Type", "application/json")
Expand Down

0 comments on commit 91c299a

Please sign in to comment.