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

Graph Client suffixing v2.0 to the tenantID #800

Closed
hazcod opened this issue Nov 6, 2024 · 2 comments
Closed

Graph Client suffixing v2.0 to the tenantID #800

hazcod opened this issue Nov 6, 2024 · 2 comments
Labels
Needs Attention 👋 question Further information is requested type:question An issue that's a question

Comments

@hazcod
Copy link

hazcod commented Nov 6, 2024

Describe the bug

An odd one, but when I call the following, 'v2.0' is suffixed to my tenantID:

FATA[0007] failed to get existing az devices             error="failed to retrieve managed devices: ClientSecretCredential authentication failed. \nGET https://login.microsoftonline.com/xxx-xxx-498f-b7a8-3a9b533bb4b2v2.0/.well-known/openid-configuration\n--------------------------------------------------------------------------------\nRESPONSE 400: 400 Bad Request\n--------------------------------------------------------------------------------\n{\n  \"error\": \"invalid_tenant\",\n  \"error_description\": \"AADSTS90002: Tenant 'xxx-xxx-498f-b7a8-3a9b533bb4b2v2.0' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant. Trace ID: 54ff98ce-381d-40a3-8ad5-ecebfc602800 Correlation ID: 40af2ef1-7d3b-426c-9bac-86f2ed499fba Timestamp: 2024-11-06 15:14:50Z\",\n  \"error_codes\": [\n    90002\n  ],\n  \"timestamp\": \"2024-11-06 15:14:50Z\",\n  \"trace_id\": \"54ff98ce-381d-40a3-8ad5-ecebfc602800\",\n  \"correlation_id\": \"40af2ef1-7d3b-426c-9bac-86f2ed499fba\",\n  \"error_uri\": \"https://login.microsoftonline.com/error?code=90002\"\n}\n--------------------------------------------------------------------------------\nTo troubleshoot, visit https://aka.ms/azsdk/go/identity/troubleshoot#client-secret"

My code:

package azure

import (
	"context"
	"fmt"
	"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
	msGraph "github.com/microsoftgraph/msgraph-sdk-go"
	"github.com/microsoftgraph/msgraph-sdk-go/devicemanagement"
	"github.com/sirupsen/logrus"
)

type Azure struct {
	logger      *logrus.Logger
	graphClient *msGraph.GraphServiceClient
}

func New(logger *logrus.Logger, tenantID, clientID, clientSecret string) (*Azure, error) {
	if logger == nil {
		logger = logrus.New()
	}

	if tenantID == "" || clientID == "" || clientSecret == "" {
		return nil, fmt.Errorf("azure: tenant id and client id and client secret are required")
	}

	azCreds, err := azidentity.NewClientSecretCredential(tenantID, clientID, clientSecret, nil)
	if err != nil {
		return nil, fmt.Errorf("could not authenticate to Azure: %v", err)
	}

	graphClient, err := msGraph.NewGraphServiceClientWithCredentials(azCreds, []string{"https://graph.microsoft.com/.default"})
	if err != nil {
		return nil, fmt.Errorf("could not create Azure client: %v", err)
	}

	_, err = graphClient.DeviceManagement().ManagedDevices().Get(context.Background(), &devicemanagement.ManagedDevicesRequestBuilderGetRequestConfiguration{
		QueryParameters: &devicemanagement.ManagedDevicesRequestBuilderGetQueryParameters{
			Select: []string{"id", "azureADDeviceId", "operatingSystem", "complianceState", "serialNumber"},
		},
	})
	if err != nil {
		return nil, fmt.Errorf("failed to retrieve managed devices: %v", err)
	}

	return &Azure{
		logger:      logger,
		graphClient: graphClient,
	}, nil
}

Expected behavior

Auth working.

How to reproduce

Run the code above.

SDK Version

v1.51.0

Latest version known to work for scenario above?

not sure

Known Workarounds

No response

Debug output

Click to expand log ```
</details>


### Configuration

- OS: macOS arm64
- Go: 1.23.2

### Other information

_No response_
@hazcod hazcod added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 6, 2024
@baywet
Copy link
Member

baywet commented Nov 10, 2024

Hi @hazcod
Thank you for using the SDK and for reaching out.

The authentication part of the SDK is handled by the Azure Identity SDK.
Can you please create another issue here so the right people can have a look at it?

Thanks!

@baywet baywet added question Further information is requested status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:bug A broken experience labels Nov 10, 2024
@hazcod
Copy link
Author

hazcod commented Nov 13, 2024

As per Azure/azure-sdk-for-go#23723 , this was a regression and is now fixed.

@hazcod hazcod closed this as completed Nov 13, 2024
@microsoft-github-policy-service microsoft-github-policy-service bot added Needs Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Attention 👋 question Further information is requested type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants