The sample app you use in this quickstart acquires an access token to call Microsoft Graph API.
To complete registration, provide the application a name and specify the supported account types. Once registered, the application Overview pane displays the identifiers needed in the application source code.
Create a client secret for the registered application. The application uses the client secret to prove its identity when it requests for tokens:
For daemon app to access data in Microsoft Graph API, you grant it the permissions it needs. The daemon app needs application type permissions. Users can't interact with a daemon application, so the tenant administrator must consent to these permissions. Use the following steps to grant and consent to the permissions:
To obtain the sample application, you can either clone it from GitHub or download it as a .zip file.
To use your app registration details in the client daemon app sample, use the following steps:
You've configured your sample app. You can proceed to run and test it.
From your console window, run the following command to build and run the application:
dotnet run
Once the application runs successfully, it displays a response similar to the following snippet (shortened for brevity):
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#applications/$entity",
"id": "00001111-aaaa-2222-bbbb-3333cccc4444",
"deletedDateTime": null,
"appId": "00001111-aaaa-2222-bbbb-3333cccc4444",
"applicationTemplateId": null,
"disabledByMicrosoftStatus": null,
"createdDateTime": "2021-01-17T15:30:55Z",
"displayName": "identity-dotnet-console-app",
"description": null,
"groupMembershipClaims": null,
...
}
A daemon application acquires a token on behalf of itself (not on behalf of a user). Users can't interact with a daemon application because it requires its own identity. This type of application requests an access token by using its application identity by presenting its application ID, credential (secret or certificate), and an application ID URI. The daemon application uses the standard OAuth 2.0 client credentials grant flow to acquire an access token.
The app acquires an access token from Microsoft identity platform. The access token is scoped for the Microsoft Graph API. The app then uses the access token to request its own application registration details from Microsoft Graph API. The app can request any resource from Microsoft Graph API as long as the access token has the right permissions.
The sample demonstrates how an unattended job or Windows service can run with an application identity, instead of a user's identity.
To install dependencies, run the following command:
npm install
Use the following command to run the application:
node . --op getUsers
If the app runs successfully, you should see a JSON formatted output representing a list of all users from your workforce tenant. It looks similar to the following snippet:
{
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users',
value: [
{
businessPhones: [],
displayName: 'Casey Jensen',
givenName: 'Jense',
jobTitle: null,
mail: null,
mobilePhone: null,
officeLocation: null,
preferredLanguage: null,
surname: 'Casey',
userPrincipalName: 'jensen@contoso.onmicrosoft.com',
id: 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb'
},
...
]
}
A daemon application acquires a token on behalf of itself (not on behalf of a user). Users can't interact with a daemon application because it requires its own identity. This type of application requests an access token by using its application identity by presenting its application ID, credential (secret or certificate), and an application ID URI. The daemon application uses the standard OAuth 2.0 client credentials grant flow to acquire an access token.
The app acquires an access token from Microsoft identity platform. The access token is scoped for the Microsoft Graph API. The app then uses the access token to read all users in the tenant from Microsoft Graph API. The app can request any resource from Microsoft Graph API as long as the access token has the right permissions. In this case, we granted the app User.Read.All app permission so that it read all users' full profiles.
The sample demonstrates how an unattended job or Windows service can run with an application identity, instead of a user's identity.
To install dependencies, run the following command:
pip install -r requirements.txt
To run the application, use the following command:
python confidential_client_secret_sample.py parameters.json
If the app runs successfully, you should see a JSON formatted output representing a list of all users from your workforce tenant. It looks similar to the following snippet:
{
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users',
value: [
{
businessPhones: [],
displayName: 'Casey Jensen',
givenName: 'Jense',
jobTitle: null,
mail: null,
mobilePhone: null,
officeLocation: null,
preferredLanguage: null,
surname: 'Casey',
userPrincipalName: 'jensen@contoso.onmicrosoft.com',
id: 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb'
},
...
]
}
A daemon application acquires a token on behalf of itself (not on behalf of a user). Users can't interact with a daemon application because it requires its own identity. This type of application requests an access token by using its application identity by presenting its application ID, credential (secret or certificate), and an application ID URI. The daemon application uses the standard OAuth 2.0 client credentials grant flow to acquire an access token.
The app acquires an access token from Microsoft identity platform. The access token is scoped for the Microsoft Graph API. The app then uses the access token to read all users in the tenant from Microsoft Graph API. The app can request any resource from Microsoft Graph API as long as the access token has the right permissions. In this case, we granted the app User.Read.All app permission so that it read all users' full profiles.
The sample demonstrates how an unattended job or Windows service can run with an application identity, instead of a user's identity.
You can test the sample app by running the main method of ClientCredentialGrant.java from your IDE or
From your console, run the following command:
$ mvn clean compile assembly:single
This command generates a msal-client-credential-secret-1.0.0.jar file in your /targets directory.
Navigate to the /targets directory, then run your Java executable file using the following command:
$ java -jar msal-client-credential-secret-1.0.0.jar
If the app runs successfully, you should see a JSON formatted output representing a list of all users from your workforce tenant. It looks similar to the following snippet:
{
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#users',
value: [
{
businessPhones: [],
displayName: 'Casey Jensen',
givenName: 'Jense',
jobTitle: null,
mail: null,
mobilePhone: null,
officeLocation: null,
preferredLanguage: null,
surname: 'Casey',
userPrincipalName: 'jensen@contoso.onmicrosoft.com',
id: 'aaaaaaaa-0000-1111-2222-bbbbbbbbbbbb'
},
...
]
}
A daemon application acquires a token on behalf of itself (not on behalf of a user). Users can't interact with a daemon application because it requires its own identity. This type of application requests an access token by using its application identity by presenting its application ID, credential (secret or certificate), and an application ID URI. The daemon application uses the standard OAuth 2.0 client credentials grant flow to acquire an access token.
The app acquires an access token from Microsoft identity platform. The access token is scoped for the Microsoft Graph API. The app then uses the access token to read all users in the tenant from Microsoft Graph API. The app can request any resource from Microsoft Graph API as long as the access token has the right permissions. In this case, we granted the app User.Read.All app permission so that it read all users' full profiles.
The sample demonstrates how an unattended job or Windows service can run with an application identity, instead of a user's identity.