【发布时间】:2017-01-12 03:54:14
【问题描述】:
我正在尝试以编程方式在 Azure AD 中创建应用程序。 我在管理门户中添加了初始应用程序并授予了 Graph Api 和 Active Directory 的权限(目录读/写两者)。
首先我获取授权码,示例 url 格式如下:
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>,
}
之后我通过以下请求获得身份验证令牌:
client = OAuth2::Client.new(client_id,
client_secret,
:site => 'https://login.microsoftonline.com',
:authorize_url => '/common/oauth2/authorize',
:token_url => '/common/oauth2/token')
auth_token = client.auth_code.get_token(auth_code,
:redirect_uri => redirect_uri,
:scope => 'openid'
最后我可以对应用程序端点进行图形 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
作为回应,我收到以下错误,描述性不强,不确定出了什么问题:
{"odata.error"=>{"code"=>"Service_InternalServerError", "message"=>{"lang"=>"en", "value"=>"Encountered an internal server error."}}}
欢迎提出任何建议。
【问题讨论】:
标签: ruby azure automation azure-active-directory azure-ad-graph-api