microsoftgraph / microsoftgraph/msgraph-beta-sdk-python

Graph API response field format mismatch with SDK object field format

未關閉
#959 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

status:waiting-for-triage type:bug
主要語言
Python
星號
44
分支
16
平均合併
20 小時 39 分鐘
30 天內合併 PR
3

描述

Describe the bug

The field in question is for Conditional Access Policies (https://graph.microsoft.com/v1.0/identity/conditionalAccess/policies): conditions.authenticationFlows.transferMethods. When specified in a policy, the graph API returns this field as a comma-separated string, e.g. "transferMethods": "deviceCodeFlow,authenticationTransfer". When parsed by this SDK in this format, ConditionalAccessPolicy.conditions.authentication_flows.transfer_methods get's incorrectly set to an empty array ([]).

The SDK expects the value of this field to be an array, rather than a comma-separated string. The following code demonstrates the incorrect and desired behaviors:

from kiota_serialization_json.json_parse_node import JsonParseNode
from msgraph_beta.generated.models.conditional_access_policy import ConditionalAccessPolicy

json_data = {
  "displayName": "Test Device Code & Authentication Transfers",
  "state": "enabled",
  "conditions": {
    ...
    "authenticationFlows": {
      "transferMethods": "deviceCodeFlow,authenticationTransfer"
    }
  },
  ...
}

msgraph_sdk_obj = JsonParseNode(json_data).get_object_value(ConditionalAccessPolicy())
# msgraph_sdk_obj.conditions.authentication_flows.transfer_methods == []

fixed_json_data = {
  ...
  "conditions": {
    ...
    "authenticationFlows": {
      "transferMethods": ["deviceCodeFlow", "authenticationTransfer"]
    }
  },
  ...
}

fixed_msgraph_sdk_obj = JsonParseNode(fixed_json_data).get_object_value(ConditionalAccessPolicy())
# fixed_msgraph_sdk_obj.conditions.authentication_flows.transfer_methods == [
#   <ConditionalAccessTransferMethods.DeviceCodeFlow: 'deviceCodeFlow'>,
#   <ConditionalAccessTransferMethods.AuthenticationTransfer: 'authenticationTransfer'>
# ]

The following screenshot shows that the API returns it in the comma-separated string format:

Image

So the issue still exists when using the msgraph-sdk API request instead of the JSON parser. e.g.

from msgraph_beta.graph_service_client import GraphServiceClient

GraphServiceClient(...).identity.conditional_access.policies.by_conditional_access_policy_id('conditionalAccessPolicy-id').get()

And in the Entra UI it looks like the following:

Image

I don't know whether this bug should be fixed in this SDK or in the Graph API itself.

Expected behavior
msgraph_sdk_cap_obj: ConditionalAccessPolicy

msgraph_sdk_cap_obj.conditions.authentication_flows.transfer_methods ==
[
  <ConditionalAccessTransferMethods.DeviceCodeFlow: 'deviceCodeFlow'>,
  <ConditionalAccessTransferMethods.AuthenticationTransfer: 'authenticationTransfer'>
]
# not []
How to reproduce

The code above can be used to reproduce.

SDK Version

1.31.0

Latest version known to work for scenario above?

No response

Known Workarounds

No response

Debug output
Click to expand for a full example JSON of a policy
{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/conditionalAccess/policies/$entity",
  "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET identity/conditionalAccess/policies('<guid>')?$select=conditions,createdDateTime",
  "templateId": null,
  "displayName": "Test Device Code & Authentication Transfers",
  "state": "enabledForReportingButNotEnforced",
  "sessionControls": null,
  "conditions": {
    "userRiskLevels": [],
    "signInRiskLevels": [],
    "clientAppTypes": ["all"],
    "servicePrincipalRiskLevels": [],
    "insiderRiskLevels": null,
    "platforms": null,
    "locations": null,
    "devices": null,
    "clientApplications": null,
    "applications": {
      "includeApplications": ["None"],
      "excludeApplications": [],
      "includeUserActions": [],
      "includeAuthenticationContextClassReferences": [],
      "applicationFilter": null
    },
    "users": {
      "includeUsers": ["All"],
      "excludeUsers": [],
      "includeGroups": [],
      "excludeGroups": [],
      "includeRoles": [],
      "excludeRoles": [],
      "includeGuestsOrExternalUsers": null,
      "excludeGuestsOrExternalUsers": null
    },
    "authenticationFlows": {
      "transferMethods": "deviceCodeFlow,authenticationTransfer"
    }
  },
  "grantControls": {
    "operator": "OR",
    "builtInControls": ["block"],
    "customAuthenticationFactors": [],
    "termsOfUse": [],
    "authenticationStrength@odata.context": "https://graph.microsoft.com/v1.0/$metadata#identity/conditionalAccess/policies('e7a127d6-b745-47da-814e-f909748cff0d')/grantControls/authenticationStrength/$entity",
    "authenticationStrength": null
  }
}
Configuration

macOS, python 3.12

Other information

No response

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

使用 JsonParseNode、ConditionalAccessPolicy 和 transferMethods 範例值重現不相符的情況,然後將其與 GraphServiceClient 要求路徑進行比較。追蹤 API 傳回逗號分隔字串時 conditions.authenticationFlows.transfer_methods 的剖析方式;完成的條件是 SDK 將傳回的方法公開為預期的 ConditionalAccessTransferMethods enum 清單。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
api
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
45/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。