Skip to content

Commit

Permalink
fix: update authority url in confidential client (#1436)
Browse files Browse the repository at this point in the history
  • Loading branch information
aramase authored Aug 14, 2024
1 parent 979a1f9 commit 6fbc034
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion examples/msal-go/token_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"context"
"fmt"
"net/url"
"os"
"time"

Expand Down Expand Up @@ -37,7 +38,12 @@ func newClientAssertionCredential(tenantID, clientID, authorityHost, file string
},
)

client, err := confidential.New(fmt.Sprintf("%s%s/oauth2/token", authorityHost, tenantID), clientID, cred)
authority, err := url.JoinPath(authorityHost, tenantID)
if err != nil {
return nil, fmt.Errorf("failed to construct authority URL: %w", err)
}

client, err := confidential.New(authority, clientID, cred)
if err != nil {
return nil, fmt.Errorf("failed to create confidential client: %w", err)
}
Expand Down
7 changes: 6 additions & 1 deletion pkg/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"strconv"
"strings"
Expand Down Expand Up @@ -197,8 +198,12 @@ func doTokenRequest(ctx context.Context, clientID, resource, tenantID, authority
cred := confidential.NewCredFromAssertionCallback(func(context.Context, confidential.AssertionRequestOptions) (string, error) {
return readJWTFromFS(tokenFilePath)
})
authority, err := url.JoinPath(authorityHost, tenantID)
if err != nil {
return nil, errors.Wrap(err, "failed to construct authority URL")
}

confidentialClientApp, err := confidential.New(fmt.Sprintf("%s%s/oauth2/token", authorityHost, tenantID), clientID, cred)
confidentialClientApp, err := confidential.New(authority, clientID, cred)
if err != nil {
return nil, errors.Wrap(err, "failed to create confidential client app")
}
Expand Down

0 comments on commit 6fbc034

Please sign in to comment.