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

Failed to get user with the graph service client #26

Closed
NikaidouShinkus opened this issue Nov 22, 2021 · 2 comments
Closed

Failed to get user with the graph service client #26

NikaidouShinkus opened this issue Nov 22, 2021 · 2 comments
Assignees
Labels
question Further information is requested

Comments

@NikaidouShinkus
Copy link

I'm trying to get user with the graph service client:

import (
	"bytes"
	"encoding/json"
	"fmt"

	azure "github.com/microsoft/kiota/authentication/go/azure"
	msgraphsdkgo "github.com/microsoftgraph/msgraph-sdk-go"

	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
)

cred, _ := azidentity.NewClientSecretCredential(
		"<my-tenant-id>",
		"<my-client-id>",
		"<my-client-secret>",
		&azidentity.ClientSecretCredentialOptions{
			AuthorityHost: azidentity.AzureChina,
		})

auth, _ := azure.NewAzureIdentityAuthenticationProviderWithScopes(cred, []string{
	"https://microsoftgraph.chinacloudapi.cn/.default",
})


adapter, _ := msgraphsdkgo.NewGraphRequestAdapter(auth)

client := msgraphsdkgo.NewGraphServiceClient(adapter)
users, _ := client.Users().Get(nil)
fmt.Println(users)

it got nil:

<nil>

but the config worked when I user Postman:
image

So I read code and see in msgraphsdkgo.NewGraphServiceClient:
image
it's https://microsoftgraph.chinacloudapi.cn/v1.0 for Azure AD of China, and it seems that I can't change this value:
image

Thanks for your attention.

@baywet
Copy link
Member

baywet commented Nov 22, 2021

Hi @NikaidouShinkus,
Thanks for reaching out.
Yes you should be able to change that value.
Just after the line where you define the client add the following line.
adapter.SetBaseUrl("https://microsoftgraph.chinaclouapi.cn/v1.0")

@baywet baywet self-assigned this Nov 22, 2021
@baywet baywet added the question Further information is requested label Nov 22, 2021
@NikaidouShinkus
Copy link
Author

Hi @baywet
Thanks again for your help. I misread NewGraphServiceClient

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants