连接第二个“静态”Azure office365帐户而无需登录(已提供凭据)的正确方法是什么?

问题描述 投票:0回答:1

我工作的公司是一个非常庞大的公司,拥有5000多名员工。因此,我们拥有Azure许可,所有电子邮件和服务器都在其平台上运行。我已经为我们的内部业务(内部网)构建了一个应用程序。此应用程序使用SSO登录我们的用户并阻止不在我们租户中的外部用户。董事会来找我,询问我们是否可以使用一个全球电子邮件帐户通过日历管理所​​有公司活动和公告。我已经搜索了一段时间(3周),找不到任何与我将要做的事情有关的事情(在PHP中)。

我需要通过php连接微软图表,自动记录“静态”给定的电子邮件地址并吐出2个日期之间的所有日历事件。微软图api充满了预览,但它都是为“公共”电子邮件地址而不是更安全的Azure电子邮件地址编写的。

我有一个带有Bearer令牌的连接集,但默认情况下返回已过期。

到目前为止我有什么:

$tenantAppUrl = "https://login.microsoftonline.com/“.$tenantid;
$tenantHostUrl = "login.microsoftonline.com”;
$requesturl = "https://login.microsoftonline.com/“.$tenantid."/oauth2/token?api-version=1.6”;

$post_params = array(
   "client_id" => $clientid,
   "client_secret" => $clientsecret,
   "resource" => "https://graph.windows.net/",
   "grant_type" => "client_credentials"
);
$headers = array(
   "POST: " . $tenantAppUrl . " HTTP/1.1",
   "Content-Type: application/x-www-form-urlencoded",
   "Host: " . $tenantHostUrl,
   "cache-control: no-cache",
   'Content-Length: ' . strlen(json_encode($post_params))
);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $fullurl);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION,true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_params);
$response = json_decode(curl_exec($curl), false);

curl_close($curl);

以上内容返回2小时前已过期的Bearer令牌。

HTTP/1.1 100 Continue HTTP/1.1 200 OK Cache-Control: no-cache, no-store Pragma: no-cache Content-Type: application/json; charset=utf-8 Expires: -1 Strict-Transport-Security: max-age=31536000; includeSubDomains X-Content-Type-Options: nosniff x-ms-request-id: 2f26979b-c336-44a3-a9c9-d4d785758c00 P3P: CP="DSP CUR OTPi IND OTRi ONL FIN" Set-Cookie: fpc=AsIZpMH6undMozQVDrbmPxTWEVd_AQAAAEeKP9QOAAAA; expires=Fri, 10-May-2019 06:55:04 GMT; path=/; secure; HttpOnly Set-Cookie: x-ms-gateway-slice=prod; path=/; secure; HttpOnly Set-Cookie: stsservicecookie=ests; path=/; secure; HttpOnly Date: Wed, 10 Apr 2019 06:55:03 GMT Content-Length: 1448 

{"token_type":"Bearer","expires_in":"3599","ext_expires_in":"3599","expires_on":"1554882904","not_before":"1554879004","resource":"https://graph.windows.net/","access_token”:”<thetoken>"}

我希望一个应该有效至少2小时的Bearer令牌,但它会在2小时前返回,而不是那个。

为什么此令牌已过期,如何在php中使用“续订”/“JWT”协议将其使用时间延长至1个月或更长时间?

请注意,此帐户不会被任何人登录。它需要自动发生。 (凭据已经(安全)保存在Intranet管理环境中)。

如何获取Azure帐户的2个日期之间的所有日历事件?下面的网址也会针对“公共电子邮件地址”进行描述。

https://docs.microsoft.com/en-us/graph/api/calendar-list-calendarview?view=graph-rest-1.0

php azure oauth-2.0 azure-active-directory bearer-token
1个回答
0
投票

要确定令牌生存期,可以使用expires_inexpires_on参数值,每个documentation

  • expires_in访问令牌有效期(以秒为单位)
  • expires_on访问令牌到期的时间。日期表示为从1970-01-01T0:0:0Z UTC到到期时间的秒数。此值用于确定缓存令牌的生存期。

在您的示例中,来自/token端点的响应告诉令牌将在3599秒之后或在2019-04-10 07:55:04(在设计的UTC中)过期

要获得本地到期时间设置DateTime::setTimezoneList of Supported Timezones),如下所示:

$expiredOn = DateTime::createFromFormat( 'U', $token->expires_on, new DateTimeZone('UTC'));
$expiredOn->setTimeZone(new DateTimeZone('Europe/Helsinki'));
© www.soinside.com 2019 - 2024. All rights reserved.