Skip to content

Commit 91c299a

Browse files
markush81peick
authored andcommitted
add client_id to support Microsoft Entra ID in int128/kubelogin
merges golang#764 (golang#764)
1 parent 49a531d commit 91c299a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

oauth2.go

+2
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ func (c *Config) Exchange(ctx context.Context, code string, opts ...AuthCodeOpti
224224
v := url.Values{
225225
"grant_type": {"authorization_code"},
226226
"code": {code},
227+
"client_id": {c.ClientID},
227228
}
228229
if c.RedirectURL != "" {
229230
v.Set("redirect_uri", c.RedirectURL)
@@ -280,6 +281,7 @@ func (tf *tokenRefresher) Token() (*Token, error) {
280281
tk, err := retrieveToken(tf.ctx, tf.conf, url.Values{
281282
"grant_type": {"refresh_token"},
282283
"refresh_token": {tf.refreshToken},
284+
"client_id": {tf.conf.ClientID},
283285
})
284286

285287
if err != nil {

oauth2_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestExchangeRequest(t *testing.T) {
108108
if err != nil {
109109
t.Errorf("Failed reading request body: %s.", err)
110110
}
111-
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
111+
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
112112
t.Errorf("Unexpected exchange payload; got %q", body)
113113
}
114114
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
@@ -152,7 +152,7 @@ func TestExchangeRequest_CustomParam(t *testing.T) {
152152
if err != nil {
153153
t.Errorf("Failed reading request body: %s.", err)
154154
}
155-
if string(body) != "code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
155+
if string(body) != "client_id=CLIENT_ID&code=exchange-code&foo=bar&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
156156
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
157157
}
158158
w.Header().Set("Content-Type", "application/x-www-form-urlencoded")
@@ -198,7 +198,7 @@ func TestExchangeRequest_JSONResponse(t *testing.T) {
198198
if err != nil {
199199
t.Errorf("Failed reading request body: %s.", err)
200200
}
201-
if string(body) != "code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
201+
if string(body) != "client_id=CLIENT_ID&code=exchange-code&grant_type=authorization_code&redirect_uri=REDIRECT_URL" {
202202
t.Errorf("Unexpected exchange payload, %v is found.", string(body))
203203
}
204204
w.Header().Set("Content-Type", "application/json")
@@ -436,7 +436,7 @@ func TestTokenRefreshRequest(t *testing.T) {
436436
t.Errorf("Unexpected Content-Type header %q", headerContentType)
437437
}
438438
body, _ := ioutil.ReadAll(r.Body)
439-
if string(body) != "grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
439+
if string(body) != "client_id=CLIENT_ID&grant_type=refresh_token&refresh_token=REFRESH_TOKEN" {
440440
t.Errorf("Unexpected refresh token payload %q", body)
441441
}
442442
w.Header().Set("Content-Type", "application/json")

0 commit comments

Comments
 (0)