代码之家  ›  专栏  ›  技术社区  ›  AlexB

Azure AD B2C-如何以编程方式添加自定义属性(扩展属性)

  •  0
  • AlexB  · 技术社区  · 7 年前

    documentation . 这是为用户添加自定义属性的正确方法吗?

    2 回复  |  直到 7 年前
        1
  •  1
  •   Anshu Kunal    7 年前

    您可以使用图形API在所需的应用程序对象上创建extensionProperty。

    POST https://graph.windows.net/contoso.onmicrosoft.com/applications/269fc2f7-6420-4ea4-be90-9e1f93a87a64/extensionProperties?api-version=1.5 HTTP/1.1
    Authorization: Bearer eyJ0eXAiOiJKV1Qi...r6Xh5KVA
    Content-Type: application/json
    Host: graph.windows.net
    Content-Length: 104
    {
    "name": "skypeId",
    "dataType": "String",
    "targetObjects": [
        "User"
    ]
    
    }
    

    如果操作成功,它将返回HTTP 201创建的状态代码以及完全限定的扩展属性名称,该名称可用于将值写入目标类型。 azure-ad-graph-api-directory-schema-extensions

        2
  •  0
  •   Pytry    7 年前

    添加属性的正确方法是通过“门户”。蔚蓝色的com的管理门户。

    在所有用户都可以使用这些属性之前,您还需要通过策略创建一个用户。

    需要考虑的另一件事是,扩展名在每个环境中都不同,因此您需要一些自定义逻辑来解析从GraphApi获得的用户JSON,并检查以确保属性以您为该属性指定的名称结尾。

    例子:

    //Java, sorry
    private YourCustomGraphApiUser populateCustomProperty(JsonNode jsonUser) throws JsonProcessingException{
    
        YourCustomGraphApiUser azureUser = mapper.treeToValue(jsonUser, YourCustomGraphApiUser.class);
        String[] customAttributeNames = new String()["one","two"]; //Replace this with some values from some injected properties
        for(String attributeName : customAttributeNames){
            JsonNode customAttribute = jsonUser.get(attributeName);
            if(customAttribute != null){
                azureUser.set(attributeName, customAttribute.asText());//Assuming custom attributes are stored in a map-like structure in YourCustomGraphApiUser. 
            }
            else{                           
                throw new NotFoundException("Error getting the name for custom attribute "+attributeName, e);
                // OR you could ignore and just log an error. Whatever.
            }           
        }
        return azureUser;
    }