Microsoft Apps Api Endpoint RuntimeError“错误” =>“代码” =>“ BadRequest”,“消息” =>“请求不适用于目标租户。”,

时间:2019-07-18 09:17:13

标签: outlook

端点:https://graph.microsoft.com/v1.0/deviceAppManagement/mobileApps

错误:

RuntimeError - {"error"=>{"code"=>"BadRequest", "message"=>"Request not applicable to target tenant.", "innerError"=>{"request-id"=>"476e2f7d-e539-4b93-82c1-45be7e0b183b", "date"=>"2019-07-18T08:21:53"}}}

我正试图从我的Microsoft帐户中获取所有应用程序,但出现运行时异常。使用相同的方法,我可以成功获取所有用户。

def admin_authorize
    client = Signet::OAuth2::Client.new(
      authorization_uri: 'https://login.microsoftonline.com/51f6420c-47a1-4701-8bf9-e5b71795f17a/adminconsent',
      client_id: CLIENT,
      redirect_uri: 'http://localhost:3000/integrations/microsoft/oauth2callback',
      state: '12345678900'
    )
    redirect_to client.authorization_uri.to_s
end

def authorize_callback
    if params[:admin_consent] == "True"
      response = token
      #users response.parsed_response["access_token"]
      apps response.parsed_response["access_token"]
    else
      redirect_to 'http://test-company.localhost:3000/dashboard'
    end
end

def token
    body = {
          grant_type: 'client_credentials',
          client_id: CLIENT,
          client_secret: SECRET,
          scope: 'https://graph.microsoft.com/.default',
          redirect_uri: 'http://localhost:3000/integrations/microsoft/oauth2callback',
        }
    headers = {'Content-Type': "application/x-www-form-urlencoded"}
    response = HTTParty.post "https://login.microsoftonline.com/#{TENANT}/oauth2/v2.0/token", headers: headers, body: body
end

def users access_token
    url = '/v1.0/users'
    response = make_api_call url, access_token
    raise response.parsed_response.to_s || "Request returned #{response.code}" unless response.code == 200
    response.parsed_response['value']
end

def apps access_token
    url = '/v1.0/deviceAppManagement/mobileApps'
    response = make_api_call url, access_token
    raise response.parsed_response.to_s || "Request returned #{response.code}" unless response.code == 200
    response.parsed_response['value']
end

def make_api_call(endpoint, token, params = nil)
    headers = {
      Authorization: "Bearer #{token}",
      'Content-Type': 'application/json'
    }
    query = params || {}
    HTTParty.get "#{GRAPH_HOST}#{endpoint}",
                    headers: headers,
                    query: query
end

1 个答案:

答案 0 :(得分:0)

所有Intune Graph API都需要Azure AD Premium P2版本。如果启用Azure AD Premium P2,它将提供输出。