使用Azure GraphClient API如何创建新的本机应用程序? [英] Using Azure GraphClient API how can you create a new Native Application?
问题描述
看起来Microsoft.Azure.ActiveDirectory.GraphClient
中的Application对象允许创建Web应用程序.我看不到如何使用它来创建新的本机应用程序.
谢谢
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
更新:
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);
}
推荐答案
应用程序是本机客户端应用程序这一事实由Application
对象上的PublicClient
布尔属性识别. (请参阅OAuth 2.0规范中的客户端类型.)
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).
有关Application
对象的这些和其他属性的详细信息,请参见API参考文档:
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
这篇关于使用Azure GraphClient API如何创建新的本机应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!