-
Notifications
You must be signed in to change notification settings - Fork 99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add disable-instance-discovery option in interactive pop mode #593
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -20,6 +20,7 @@ ZURE_CLIENT_CERTIFICATE_PASSWORD environment variable | |||||
--client-id string AAD client application ID. It may be specified in AAD_SERVICE_PRINCIPAL_CLIENT_ID or AZURE_CLIENT_ID environment variable | ||||||
--client-secret string AAD client application secret. Used in spn login. It may be specified in AAD_SERVICE_PRINCIPAL_CLIENT_SECRET or AZURE_CLIENT_S | ||||||
ECRET environment variable | ||||||
--disable-instance-discovery set to true to disable instance discovery in environments with their own simple Identity Provider (not AAD) that do not have instance metadata discovery endpoint. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-e, --environment string Azure environment name (default "AzurePublicCloud") | ||||||
--federated-token-file string Workload Identity federated token file. It may be specified in AZURE_FEDERATED_TOKEN_FILE environment variable | ||||||
-h, --help help for get-token | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,19 +9,24 @@ import ( | |
"github.com/AzureAD/microsoft-authentication-library-for-go/apps/public" | ||
) | ||
|
||
type PublicClientOptions struct { | ||
Authority string | ||
ClientID string | ||
DisableInstanceDiscovery bool | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dont we also need TenantId here? wondering as I introduced MsalClientOptions in my other PR and the possibility of reusing it here.. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1. why don't we have https://pkg.go.dev/github.com/AzureAD/[email protected]/apps/public#WithTenantID |
||
Options *azcore.ClientOptions | ||
} | ||
|
||
// AcquirePoPTokenInteractive acquires a PoP token using MSAL's interactive login flow. | ||
// Requires user to authenticate via browser | ||
func AcquirePoPTokenInteractive( | ||
context context.Context, | ||
popClaims map[string]string, | ||
scopes []string, | ||
authority, | ||
clientID string, | ||
options *azcore.ClientOptions, | ||
pcOptions *PublicClientOptions, | ||
) (string, int64, error) { | ||
var client *public.Client | ||
var err error | ||
client, err = getPublicClient(authority, clientID, options) | ||
client, err = getPublicClient(pcOptions) | ||
if err != nil { | ||
return "", -1, err | ||
} | ||
|
@@ -53,13 +58,11 @@ func AcquirePoPTokenByUsernamePassword( | |
context context.Context, | ||
popClaims map[string]string, | ||
scopes []string, | ||
authority, | ||
clientID, | ||
username, | ||
password string, | ||
options *azcore.ClientOptions, | ||
pcOptions *PublicClientOptions, | ||
) (string, int64, error) { | ||
client, err := getPublicClient(authority, clientID, options) | ||
client, err := getPublicClient(pcOptions) | ||
if err != nil { | ||
return "", -1, err | ||
} | ||
|
@@ -88,23 +91,25 @@ func AcquirePoPTokenByUsernamePassword( | |
} | ||
|
||
// getPublicClient returns an instance of the msal `public` client based on the provided options | ||
func getPublicClient( | ||
authority, | ||
clientID string, | ||
options *azcore.ClientOptions, | ||
) (*public.Client, error) { | ||
// The instance discovery will be disable on private cloud | ||
func getPublicClient(pcOptions *PublicClientOptions) (*public.Client, error) { | ||
var client public.Client | ||
var err error | ||
if options != nil && options.Transport != nil { | ||
if pcOptions == nil { | ||
return nil, fmt.Errorf("unable to create public client: publicClientOptions is empty") | ||
} | ||
if pcOptions.Options != nil && pcOptions.Options.Transport != nil { | ||
client, err = public.New( | ||
clientID, | ||
public.WithAuthority(authority), | ||
public.WithHTTPClient(options.Transport.(*http.Client)), | ||
pcOptions.ClientID, | ||
public.WithAuthority(pcOptions.Authority), | ||
public.WithHTTPClient(pcOptions.Options.Transport.(*http.Client)), | ||
public.WithInstanceDiscovery(!pcOptions.DisableInstanceDiscovery), | ||
) | ||
} else { | ||
client, err = public.New( | ||
clientID, | ||
public.WithAuthority(authority), | ||
pcOptions.ClientID, | ||
public.WithAuthority(pcOptions.Authority), | ||
public.WithInstanceDiscovery(!pcOptions.DisableInstanceDiscovery), | ||
) | ||
} | ||
if err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what do you mean by
simple
?