Ruby 获得';服务内部服务器错误';在Azure AD中通过图形API创建应用程序时
我正在尝试以编程方式在Azure AD中创建应用程序。 我在管理门户中添加了初始应用程序,并授予了Graph Api和Active directory的权限(两者都是目录读/写) 首先,我获取授权码,url格式示例如下:Ruby 获得';服务内部服务器错误';在Azure AD中通过图形API创建应用程序时,ruby,azure,automation,azure-active-directory,azure-ad-graph-api,Ruby,Azure,Automation,Azure Active Directory,Azure Ad Graph Api,我正在尝试以编程方式在Azure AD中创建应用程序。 我在管理门户中添加了初始应用程序,并授予了Graph Api和Active directory的权限(两者都是目录读/写) 首先,我获取授权码,url格式示例如下: uri = Addressable::URI.parse('https://login.microsoftonline.com/common/oauth2/authorize') uri.query_values = { response_type: 'code',
uri = Addressable::URI.parse('https://login.microsoftonline.com/common/oauth2/authorize')
uri.query_values = {
response_type: 'code',
response_mode: 'form_post',
client_id: <Application ID>,
redirect_uri: <Redirect URI>,
resource: 'https://graph.windows.net/',
state: <UUID>,
}
最后,我可以对应用程序端点进行graph api调用以添加应用程序:
graph_url = 'https://graph.windows.net/<TENANT ID>/applications?api-version=1.6'
body = {
'identifierUris' => ['<URI>'],
'availableToOtherTenants' => true,
'homepage' => <Home PAGE>,
'replyURLs' => <SOME REPLY URL>,
'displayName' => <APP DISPLAY NAME>,
}
headers = {'Content-Type' => 'application/json','Authorization' => "Bearer #{auth_token.token}"}
conn = Faraday.new(graph_url, {headers: headers})
res = conn.post graph_url, body.to_json
非常感谢您的建议。我修复了我的问题,在尝试创建应用程序时出现了内部错误。 为http请求形成“正文”时要小心。我在“replyUrls”属性的url末尾添加了额外的“/”。为每个属性添加数据类型也很重要。以下是对我有效的示例请求:
body = {
"odata.type" => "Microsoft.DirectoryServices.Application",
"identifierUris" => ["https://mynamehere.com/#{someidentifier}"],
"identifierUris@odata.type" => "Collection(Edm.String)",
"availableToOtherTenants" => true,
"homepage" => 'https://myhomepage.com',
"replyURLs" => ["http://localhost:3000/someUrl"],
"replyURLs@odata.type" => "Collection(Edm.String)",
"displayName" => 'This is my app',
}
以下是有帮助的博客链接:
很高兴您能够解决此问题。我在过去发现,避免此类问题的一个非常简单的方法是,首先对类似的对象执行“GET”,然后修改该对象以包含所需的新属性,然后将其用于您的帖子。例如,我将使用Azure门户创建一个应用程序,然后使用该应用程序的框架在我的POST请求中创建新应用程序。另一个技巧可能是使用Fiddler捕获PowerShell的HTTP流量,或者使用另一个可以使用graph创建应用程序的服务,然后使用它来帮助创建身体。感谢您提供的技巧,我们将在将来记住它!
{"odata.error"=>{"code"=>"Service_InternalServerError", "message"=>{"lang"=>"en", "value"=>"Encountered an internal server error."}}}
body = {
"odata.type" => "Microsoft.DirectoryServices.Application",
"identifierUris" => ["https://mynamehere.com/#{someidentifier}"],
"identifierUris@odata.type" => "Collection(Edm.String)",
"availableToOtherTenants" => true,
"homepage" => 'https://myhomepage.com',
"replyURLs" => ["http://localhost:3000/someUrl"],
"replyURLs@odata.type" => "Collection(Edm.String)",
"displayName" => 'This is my app',
}