How to access Microsoft Graph

Sally Chen 145 Reputation points Microsoft External Staff
2024-12-13T10:32:43.3266667+00:00

I am building a Teams extension with Microsoft Graph. I use the following code to create a client.

// Initialize DeviceCodeCredential
const credential = new DeviceCodeCredential({
  tenantId: config.tenantId,
  clientId: config.clientId,
  userPromptCallback: (info) => {
    console.log(info.message); // Display the device code message to the user
  },
});

// Create authentication provider for Microsoft Graph
const authProvider = new TokenCredentialAuthenticationProvider(credential, {
  scopes: ['User.Read'], // Specify the required scopes
});

// Initialize Microsoft Graph client
const graphClient = Client.initWithMiddleware({ authProvider: authProvider });

It asked me to sign in: To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXX to authenticate.

However, after I signed in, the message said that

Please help us maintain device security. Login was successful, but the system administrator requires that the device requesting access must be managed by Microsoft Non-Production to access this resource. Error Code: 530033 Request Id: 4e72476c-27f8-4da4-81e5-6b8c35476900 Correlation Id: a8162939-754f-4ca9-9ef8-5140fd6c42c4 Timestamp: 2024-12-13T10:25:43.024Z 應用程式名稱: Microsoft Azure CLI 應用程式識別碼: 04b07795-8ddb-461a-bbee-02f9e1bf7b46 IP 位址: 2404:f801:8050:3:13b:4377:414e:10a4 裝置識別碼: 3c811fad-a468-42a4-946a-7c468a8bb797 裝置平台: Windows 10 裝置狀態: Compliant

User's image

How do I solve this issue and use Microsoft Graph sucessfully?

Thank you.

Microsoft Security Microsoft Graph
{count} votes

Accepted answer
  1. Vasil Michev 119.5K Reputation points MVP Volunteer Moderator
    2024-12-13T16:12:17.9633333+00:00

    Talk to your IT Support staff, they have configured policy that prevents token issuing for non-managed devices. Or consider leveraging the client credentials flow instead, so that no user/device component is involved.

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.