in pkg/internal/token/adaldevicecodecredential.go [52:73]
func (c *ADALDeviceCodeCredential) GetToken(ctx context.Context, opts policy.TokenRequestOptions) (azcore.AccessToken, error) {
client := &autorest.Client{}
// to keep backward compatibility,
// 1. we only support one resource
// 2. we remove the "/.default" suffix from the resource
resource := strings.Replace(opts.Scopes[0], "/.default", "", 1)
deviceCode, err := adal.InitiateDeviceAuth(client, c.oAuthConfig, c.clientID, resource)
if err != nil {
return azcore.AccessToken{}, fmt.Errorf("initialing the device code authentication: %w", err)
}
if _, err := fmt.Fprintln(os.Stderr, *deviceCode.Message); err != nil {
return azcore.AccessToken{}, fmt.Errorf("prompting the device code message: %w", err)
}
token, err := adal.WaitForUserCompletionWithContext(ctx, client, deviceCode)
if err != nil {
return azcore.AccessToken{}, fmt.Errorf("waiting for device code authentication to complete: %w", err)
}
return azcore.AccessToken{Token: token.AccessToken, ExpiresOn: token.Expires()}, nil
}