Using Azure GraphClient API how can you create a new Native Application?

纵饮孤独 提交于 2020-01-25 20:39:28

问题


It looks like the Application object in Microsoft.Azure.ActiveDirectory.GraphClient allows a Webapplication to be created. I cannot see how I can use this to create a new Native application. thanks

Updates:

TaskCompletionSource<string> tcs = new TaskCompletionSource<string>();
tcs.SetResult(accessToken);
var graphClient = new ActiveDirectoryClient(
    new Uri($"{GraphApiBaseUrl}{tenantId}"),
    async () => { return await tcs.Task; });
var password = Guid.NewGuid().ToString("N");
var cred = new PasswordCredential()
{
    StartDate = DateTime.UtcNow,
    EndDate = DateTime.UtcNow.AddYears(1),
    Value = password
};
var app = await GetApplicationByUrlAsync(accessToken, tenantId, appName, identifierUrl);
if(app == null)
{
    app = new Application()
    {
        DisplayName = appName,
        Homepage = homePageUrl,
        IdentifierUris = new List<string>() { identifierUrl },
        LogoutUrl = logoutUrl,
        ReplyUrls = new List<string>() { replyUrl },
        PasswordCredentials = new List<PasswordCredential>() { cred },
    };
    await graphClient.Applications.AddApplicationAsync(app);
}

回答1:


The fact that an app is a native client application is identified by the PublicClient boolean property on the Application object. (See client types from the OAuth 2.0 spec.)

So, you could register a native client app with the following code:

var app = new Application()
{
    DisplayName = "My native client app",
    ReplyUrls = new List<string>() { "urn:ietf:wg:oauth:2.0:oob" },
    PublicClient = true
};

await graphClient.Applications.AddApplicationAsync(app);

Console.WriteLine("App created. AppId: {0}, ObjectId: {1}", app.AppId, app.ObjectId);

Note that the native client app does not have password credentials or key credentials (or any other secret).

Details about these and other properties of Application objects are available in the API reference documentation: https://msdn.microsoft.com/en-us/library/azure/ad/graph/api/entity-and-complex-type-reference#application-entity



来源:https://stackoverflow.com/questions/39260721/using-azure-graphclient-api-how-can-you-create-a-new-native-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!