Skip to content
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

Transport dialer: setting nil for wasm build #21451

Merged
merged 2 commits into from
Sep 5, 2023

Conversation

magodo
Copy link
Contributor

@magodo magodo commented Aug 28, 2023

This PR is to make this SDK to work as an WASM module. The implementation is refered from https://github.com/golang/go/blob/071aed2aaa0ed819582c5bff44b70d43c61f504a/src/net/http/transport.go#L45.

  • The purpose of this PR is explained in this or a referenced issue.
  • The PR does not update generated files.
  • Tests are included and/or updated for code changes.
  • Updates to module CHANGELOG.md are included.
  • MIT license headers are included in each file.

@jhendrixMSFT
Copy link
Member

Can we get more info on what this fixes and why it's needed please?

@magodo
Copy link
Contributor Author

magodo commented Aug 29, 2023

@jhendrixMSFT I'm trying to build some toolings that are based on this SDK to WASM to be able to run in the browser. Say I have the following simplistic code:

func main() {
	tenantID := os.Getenv("ARM_TENANT_ID")
	clientID := os.Getenv("ARM_CLIENT_ID")
	secret := os.Getenv("ARM_CLIENT_SECRET")

	cred, err := azidentity.NewClientSecretCredential(tenantID, clientID, secret, nil)
	if err != nil {
		log.Fatal(err)
	}
	tk, err := cred.GetToken(context.TODO(), policy.TokenRequestOptions{
		Scopes: []string{"https://management.core.windows.net//.default"},
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(tk)
}

It failed with following error:

2023/08/29 09:20:38 ClientSecretCredential: unable to resolve an endpoint: server response error:
 Get "https://login.microsoftonline.com/xxxx/v2.0/.well-known/openid-configuration": dial tcp: lookup login.microsoftonline.com: Protocol not available

The reason is that the browser APIs do not allow arbitrary TCP/IP connections and therefore WASM is equally limited. The Go standard net/http library hence conditionally build the default client to mitigate this issue.

So with this change, we can then successfully send above request. Though, in order to have successfully get the token, it will need some other tricks to make it work. It is another story off this topic then.

@magodo
Copy link
Contributor Author

magodo commented Sep 4, 2023

Can we settle done this PR soon? As the CI sends a ton of notifications for some weired faliure like this: https://github.com/magodo/azure-sdk-for-go/actions/runs/6048886404

@jhendrixMSFT
Copy link
Member

I was waiting for you to merge it, I'll merge it now.

@jhendrixMSFT jhendrixMSFT merged commit 68baa6f into Azure:main Sep 5, 2023
jhendrixMSFT pushed a commit that referenced this pull request Sep 6, 2023
* Transport dialer: setting nil for wasm build

* license
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants