How to create app registration using Azure SDK
I need to create an app registration with Azure AD using Azure SDK (or using rest api call, if it's not possible with SDK)
normally you do it manually using portal:
or calling Azure CLI command az ad app create
How can I do it from SDK or REST service


add a comment |
I need to create an app registration with Azure AD using Azure SDK (or using rest api call, if it's not possible with SDK)
normally you do it manually using portal:
or calling Azure CLI command az ad app create
How can I do it from SDK or REST service


add a comment |
I need to create an app registration with Azure AD using Azure SDK (or using rest api call, if it's not possible with SDK)
normally you do it manually using portal:
or calling Azure CLI command az ad app create
How can I do it from SDK or REST service


I need to create an app registration with Azure AD using Azure SDK (or using rest api call, if it's not possible with SDK)
normally you do it manually using portal:
or calling Azure CLI command az ad app create
How can I do it from SDK or REST service




edited Nov 22 '18 at 9:54


Rohit Saigal
3,2322218
3,2322218
asked Nov 21 '18 at 15:30
DziorDzior
649416
649416
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
There are 2 possible ways to do this. You can pick what works based on your scenario.
Microsoft Graph API Beta Endpoint
Microsoft Graph API Beta endpoint and working with Application resource (as answered by Jean-Marc Prieur earlier too).
POST https://graph.microsoft.com/beta/applications
NOTE: This would work but caveat being it's a beta endpoint. So if you're doing this for testing/learning that's fine but if you plan to use it for production application code it would not be recommended.
See Microsoft Graph beta endpoint documentation itself to see Microsoft's recommendation.
Also note that since currently this functionality is in Beta, you won't be able to use the Microsoft Graph .NET Client Library, but once it's released for general availability, even Client Library will probably be refreshed to support these operations.
See this SO post by Marc LaFleur with similar context.
Azure AD Graph API
Azure AD Graph API which is an older API and Microsoft Graph API is newer and recommended one for any operations possible. Your case just happens to be one where Microsoft Graph API stable version (v1.0) has not caught up yet and that functionality is only available in beta, hence for production version code you should still use older Azure AD Graph API or it's client library. Read about comparisons and special use cases here
You can use Azure AD Graph API and Application entity. POST operation can help you create an application.
POST https://graph.windows.net/{tenant-id}/applications?api-version=1.6
Read about the details: Application Entity - Azure AD Graph API
You can choose to call this API directly or make use of Azure AD Graph Client Library
Here is a quick and dirty sample code (C#) to create an Azure AD application
Notice that I've kept app.PublicClient flag as true to register as a native application. You can set it to false if you want to register it as a web application.
Setup: I have an application registered in Azure AD, which has required permissions as application permission - Read and Write all applications and grant permissions is done for this app. Now using this application's client id and client secret, a token is acquired and Azure AD Graph API is called to create an application. It is not mandatory to use application permissions, you can also use delegated permissions by prompting user for credentials. See links to two more detailed examples (old ones but still useful).
Console Application using Graph client library
Web app calls Graph using Graph client library
Azure AD Graph Client Library 2.0 Announcement page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace CreateAzureADApplication
{
class Program
{
static void Main(string args)
{
ActiveDirectoryClient directoryClient;
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{yourAADGUID}"),
async () => await GetTokenForApplication());
Application app = new Application();
app.DisplayName = "My Azure AD Native App";
app.PublicClient = true;
app.Homepage = "https://myazureadnativeapp";
activeDirectoryClient.Applications.AddApplicationAsync(app).GetAwaiter().GetResult();
}
public static async Task<string> GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.microsoftonline.com/{yourAADGUID}",
false);
// Configuration for OAuth client credentials
ClientCredential clientCred = new ClientCredential("yourappclientId",
"yourappclientsecret"
);
AuthenticationResult authenticationResult =
await authenticationContext.AcquireTokenAsync("https://graph.windows.net", clientCred);
return authenticationResult.AccessToken;
}
}
}
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
add a comment |
You can use the Microsoft Graph API.
The API to use to create an app is: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/application_post_applications
and more generally to manipulate apps: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/application
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415406%2fhow-to-create-app-registration-using-azure-sdk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
There are 2 possible ways to do this. You can pick what works based on your scenario.
Microsoft Graph API Beta Endpoint
Microsoft Graph API Beta endpoint and working with Application resource (as answered by Jean-Marc Prieur earlier too).
POST https://graph.microsoft.com/beta/applications
NOTE: This would work but caveat being it's a beta endpoint. So if you're doing this for testing/learning that's fine but if you plan to use it for production application code it would not be recommended.
See Microsoft Graph beta endpoint documentation itself to see Microsoft's recommendation.
Also note that since currently this functionality is in Beta, you won't be able to use the Microsoft Graph .NET Client Library, but once it's released for general availability, even Client Library will probably be refreshed to support these operations.
See this SO post by Marc LaFleur with similar context.
Azure AD Graph API
Azure AD Graph API which is an older API and Microsoft Graph API is newer and recommended one for any operations possible. Your case just happens to be one where Microsoft Graph API stable version (v1.0) has not caught up yet and that functionality is only available in beta, hence for production version code you should still use older Azure AD Graph API or it's client library. Read about comparisons and special use cases here
You can use Azure AD Graph API and Application entity. POST operation can help you create an application.
POST https://graph.windows.net/{tenant-id}/applications?api-version=1.6
Read about the details: Application Entity - Azure AD Graph API
You can choose to call this API directly or make use of Azure AD Graph Client Library
Here is a quick and dirty sample code (C#) to create an Azure AD application
Notice that I've kept app.PublicClient flag as true to register as a native application. You can set it to false if you want to register it as a web application.
Setup: I have an application registered in Azure AD, which has required permissions as application permission - Read and Write all applications and grant permissions is done for this app. Now using this application's client id and client secret, a token is acquired and Azure AD Graph API is called to create an application. It is not mandatory to use application permissions, you can also use delegated permissions by prompting user for credentials. See links to two more detailed examples (old ones but still useful).
Console Application using Graph client library
Web app calls Graph using Graph client library
Azure AD Graph Client Library 2.0 Announcement page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace CreateAzureADApplication
{
class Program
{
static void Main(string args)
{
ActiveDirectoryClient directoryClient;
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{yourAADGUID}"),
async () => await GetTokenForApplication());
Application app = new Application();
app.DisplayName = "My Azure AD Native App";
app.PublicClient = true;
app.Homepage = "https://myazureadnativeapp";
activeDirectoryClient.Applications.AddApplicationAsync(app).GetAwaiter().GetResult();
}
public static async Task<string> GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.microsoftonline.com/{yourAADGUID}",
false);
// Configuration for OAuth client credentials
ClientCredential clientCred = new ClientCredential("yourappclientId",
"yourappclientsecret"
);
AuthenticationResult authenticationResult =
await authenticationContext.AcquireTokenAsync("https://graph.windows.net", clientCred);
return authenticationResult.AccessToken;
}
}
}
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
add a comment |
There are 2 possible ways to do this. You can pick what works based on your scenario.
Microsoft Graph API Beta Endpoint
Microsoft Graph API Beta endpoint and working with Application resource (as answered by Jean-Marc Prieur earlier too).
POST https://graph.microsoft.com/beta/applications
NOTE: This would work but caveat being it's a beta endpoint. So if you're doing this for testing/learning that's fine but if you plan to use it for production application code it would not be recommended.
See Microsoft Graph beta endpoint documentation itself to see Microsoft's recommendation.
Also note that since currently this functionality is in Beta, you won't be able to use the Microsoft Graph .NET Client Library, but once it's released for general availability, even Client Library will probably be refreshed to support these operations.
See this SO post by Marc LaFleur with similar context.
Azure AD Graph API
Azure AD Graph API which is an older API and Microsoft Graph API is newer and recommended one for any operations possible. Your case just happens to be one where Microsoft Graph API stable version (v1.0) has not caught up yet and that functionality is only available in beta, hence for production version code you should still use older Azure AD Graph API or it's client library. Read about comparisons and special use cases here
You can use Azure AD Graph API and Application entity. POST operation can help you create an application.
POST https://graph.windows.net/{tenant-id}/applications?api-version=1.6
Read about the details: Application Entity - Azure AD Graph API
You can choose to call this API directly or make use of Azure AD Graph Client Library
Here is a quick and dirty sample code (C#) to create an Azure AD application
Notice that I've kept app.PublicClient flag as true to register as a native application. You can set it to false if you want to register it as a web application.
Setup: I have an application registered in Azure AD, which has required permissions as application permission - Read and Write all applications and grant permissions is done for this app. Now using this application's client id and client secret, a token is acquired and Azure AD Graph API is called to create an application. It is not mandatory to use application permissions, you can also use delegated permissions by prompting user for credentials. See links to two more detailed examples (old ones but still useful).
Console Application using Graph client library
Web app calls Graph using Graph client library
Azure AD Graph Client Library 2.0 Announcement page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace CreateAzureADApplication
{
class Program
{
static void Main(string args)
{
ActiveDirectoryClient directoryClient;
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{yourAADGUID}"),
async () => await GetTokenForApplication());
Application app = new Application();
app.DisplayName = "My Azure AD Native App";
app.PublicClient = true;
app.Homepage = "https://myazureadnativeapp";
activeDirectoryClient.Applications.AddApplicationAsync(app).GetAwaiter().GetResult();
}
public static async Task<string> GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.microsoftonline.com/{yourAADGUID}",
false);
// Configuration for OAuth client credentials
ClientCredential clientCred = new ClientCredential("yourappclientId",
"yourappclientsecret"
);
AuthenticationResult authenticationResult =
await authenticationContext.AcquireTokenAsync("https://graph.windows.net", clientCred);
return authenticationResult.AccessToken;
}
}
}
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
add a comment |
There are 2 possible ways to do this. You can pick what works based on your scenario.
Microsoft Graph API Beta Endpoint
Microsoft Graph API Beta endpoint and working with Application resource (as answered by Jean-Marc Prieur earlier too).
POST https://graph.microsoft.com/beta/applications
NOTE: This would work but caveat being it's a beta endpoint. So if you're doing this for testing/learning that's fine but if you plan to use it for production application code it would not be recommended.
See Microsoft Graph beta endpoint documentation itself to see Microsoft's recommendation.
Also note that since currently this functionality is in Beta, you won't be able to use the Microsoft Graph .NET Client Library, but once it's released for general availability, even Client Library will probably be refreshed to support these operations.
See this SO post by Marc LaFleur with similar context.
Azure AD Graph API
Azure AD Graph API which is an older API and Microsoft Graph API is newer and recommended one for any operations possible. Your case just happens to be one where Microsoft Graph API stable version (v1.0) has not caught up yet and that functionality is only available in beta, hence for production version code you should still use older Azure AD Graph API or it's client library. Read about comparisons and special use cases here
You can use Azure AD Graph API and Application entity. POST operation can help you create an application.
POST https://graph.windows.net/{tenant-id}/applications?api-version=1.6
Read about the details: Application Entity - Azure AD Graph API
You can choose to call this API directly or make use of Azure AD Graph Client Library
Here is a quick and dirty sample code (C#) to create an Azure AD application
Notice that I've kept app.PublicClient flag as true to register as a native application. You can set it to false if you want to register it as a web application.
Setup: I have an application registered in Azure AD, which has required permissions as application permission - Read and Write all applications and grant permissions is done for this app. Now using this application's client id and client secret, a token is acquired and Azure AD Graph API is called to create an application. It is not mandatory to use application permissions, you can also use delegated permissions by prompting user for credentials. See links to two more detailed examples (old ones but still useful).
Console Application using Graph client library
Web app calls Graph using Graph client library
Azure AD Graph Client Library 2.0 Announcement page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace CreateAzureADApplication
{
class Program
{
static void Main(string args)
{
ActiveDirectoryClient directoryClient;
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{yourAADGUID}"),
async () => await GetTokenForApplication());
Application app = new Application();
app.DisplayName = "My Azure AD Native App";
app.PublicClient = true;
app.Homepage = "https://myazureadnativeapp";
activeDirectoryClient.Applications.AddApplicationAsync(app).GetAwaiter().GetResult();
}
public static async Task<string> GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.microsoftonline.com/{yourAADGUID}",
false);
// Configuration for OAuth client credentials
ClientCredential clientCred = new ClientCredential("yourappclientId",
"yourappclientsecret"
);
AuthenticationResult authenticationResult =
await authenticationContext.AcquireTokenAsync("https://graph.windows.net", clientCred);
return authenticationResult.AccessToken;
}
}
}
There are 2 possible ways to do this. You can pick what works based on your scenario.
Microsoft Graph API Beta Endpoint
Microsoft Graph API Beta endpoint and working with Application resource (as answered by Jean-Marc Prieur earlier too).
POST https://graph.microsoft.com/beta/applications
NOTE: This would work but caveat being it's a beta endpoint. So if you're doing this for testing/learning that's fine but if you plan to use it for production application code it would not be recommended.
See Microsoft Graph beta endpoint documentation itself to see Microsoft's recommendation.
Also note that since currently this functionality is in Beta, you won't be able to use the Microsoft Graph .NET Client Library, but once it's released for general availability, even Client Library will probably be refreshed to support these operations.
See this SO post by Marc LaFleur with similar context.
Azure AD Graph API
Azure AD Graph API which is an older API and Microsoft Graph API is newer and recommended one for any operations possible. Your case just happens to be one where Microsoft Graph API stable version (v1.0) has not caught up yet and that functionality is only available in beta, hence for production version code you should still use older Azure AD Graph API or it's client library. Read about comparisons and special use cases here
You can use Azure AD Graph API and Application entity. POST operation can help you create an application.
POST https://graph.windows.net/{tenant-id}/applications?api-version=1.6
Read about the details: Application Entity - Azure AD Graph API
You can choose to call this API directly or make use of Azure AD Graph Client Library
Here is a quick and dirty sample code (C#) to create an Azure AD application
Notice that I've kept app.PublicClient flag as true to register as a native application. You can set it to false if you want to register it as a web application.
Setup: I have an application registered in Azure AD, which has required permissions as application permission - Read and Write all applications and grant permissions is done for this app. Now using this application's client id and client secret, a token is acquired and Azure AD Graph API is called to create an application. It is not mandatory to use application permissions, you can also use delegated permissions by prompting user for credentials. See links to two more detailed examples (old ones but still useful).
Console Application using Graph client library
Web app calls Graph using Graph client library
Azure AD Graph Client Library 2.0 Announcement page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Azure.ActiveDirectory.GraphClient;
using Microsoft.IdentityModel.Clients.ActiveDirectory;
namespace CreateAzureADApplication
{
class Program
{
static void Main(string args)
{
ActiveDirectoryClient directoryClient;
ActiveDirectoryClient activeDirectoryClient = new ActiveDirectoryClient(new Uri("https://graph.windows.net/{yourAADGUID}"),
async () => await GetTokenForApplication());
Application app = new Application();
app.DisplayName = "My Azure AD Native App";
app.PublicClient = true;
app.Homepage = "https://myazureadnativeapp";
activeDirectoryClient.Applications.AddApplicationAsync(app).GetAwaiter().GetResult();
}
public static async Task<string> GetTokenForApplication()
{
AuthenticationContext authenticationContext = new AuthenticationContext(
"https://login.microsoftonline.com/{yourAADGUID}",
false);
// Configuration for OAuth client credentials
ClientCredential clientCred = new ClientCredential("yourappclientId",
"yourappclientsecret"
);
AuthenticationResult authenticationResult =
await authenticationContext.AcquireTokenAsync("https://graph.windows.net", clientCred);
return authenticationResult.AccessToken;
}
}
}
edited Nov 22 '18 at 9:59
answered Nov 22 '18 at 9:52


Rohit SaigalRohit Saigal
3,2322218
3,2322218
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
add a comment |
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
Wonderful answer. That works perfectly! Thank you!
– Dzior
Nov 23 '18 at 14:54
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
You’re welcome :)
– Rohit Saigal
Nov 23 '18 at 16:58
add a comment |
You can use the Microsoft Graph API.
The API to use to create an app is: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/application_post_applications
and more generally to manipulate apps: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/application
add a comment |
You can use the Microsoft Graph API.
The API to use to create an app is: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/application_post_applications
and more generally to manipulate apps: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/application
add a comment |
You can use the Microsoft Graph API.
The API to use to create an app is: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/application_post_applications
and more generally to manipulate apps: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/application
You can use the Microsoft Graph API.
The API to use to create an app is: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/api/application_post_applications
and more generally to manipulate apps: https://developer.microsoft.com/en-us/graph/docs/api-reference/beta/resources/application
answered Nov 21 '18 at 15:50


Jean-Marc PrieurJean-Marc Prieur
76037
76037
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415406%2fhow-to-create-app-registration-using-azure-sdk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown