2017-10-11 132 views
1

我正嘗試使用Graph API創建用戶。用戶json對象如下所示。我創建了一個名爲Role的自定義屬性。因此,在創建用戶時,我需要給出一些值Role。但是,如果我包含這個自定義屬性,我得到錯誤。使用圖形API在Azure AD B2C中創建具有自定義屬性的用戶

一個或多個屬性無效

創建用戶是成功的,如果我不指定該自定義屬性。

var jsonObject = new JObject 
      { 
       {"accountEnabled", true}, 
       {"country", "India"}, 
       {"creationType", "LocalAccount"}, 
       {"givenName","given"}, 
       {"surName","surname"}, 
       {"extension_Role","Admin"}, 
       {"displayName","[email protected]"}, 
       {"passwordPolicies", "DisablePasswordExpiration,DisableStrongPassword"}, 
       {"passwordProfile", new JObject 
       { 
        {"password", "[email protected]"}, 
        {"forceChangePasswordNextLogin", false} 
       } }, 
       {"signInNames", new JArray 
        { 
         new JObject 
         { 
          {"value", "[email protected]"}, 
          {"type", "emailAddress"} 
         } 
        } 
       } 
      }; 

extension_Role是拋出錯誤的屬性。我試着給extension_appId_Role。它提供了不同的錯誤說

沒有擴展屬性這個名字

我想我們不能添加在創建用戶自定義屬性的存在。只有我們可以使用編輯配置文件更新它們糾正我,如果我錯了。我已將此自定義屬性添加到sign-upedit-profile政策中並作爲聲明。

注意:我賦予了圖API的適當權限,並使用應用程序註冊門戶註冊了一個應用程序。

回答:我找到了答案。但不知道這是否是正確的行爲。我可以插入自定義屬性,當我追加它與b2c-extensions-app應用程序ID。我在App Registrations下注冊了一個單獨的應用程序,但不知道爲什麼它仍然採用default b2c-extensions-app應用程序ID。可能是因爲我在註冊應用程序App Registrations之前創建了自定義用戶屬性。

+0

我剛剛創建了一個自定義屬性'extension_ [guid] _my_attribute'的用戶。 – spottedmahn

+0

您是否閱讀過[本文檔](https://docs.microsoft.com/zh-cn/)COM/EN-US /天藍色/主動目錄B2C /主動目錄B2C-devquickstarts-圖形的DOTNET#使用定製的屬性)? – spottedmahn

+0

您使用自定義策略還是內置策略? – spottedmahn

回答

0

如果您使用的是內置策略,則無法控制它用於存儲的應用程序custom attributes

如果您使用custom policies,see this guide來配置它用來存儲自定義屬性的應用程序。

<ClaimsProviders> 
    <ClaimsProvider> 
      <DisplayName>Azure Active Directory</DisplayName> 
     <TechnicalProfile Id="AAD-Common"> 
      <DisplayName>Azure Active Directory</DisplayName> 
      <Protocol Name="Proprietary" Handler="Web.TPEngine.Providers.AzureActiveDirectoryProvider, Web.TPEngine, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /> 
      <!-- Provide objectId and appId before using extension properties. --> 
      <Metadata> 
      <Item Key="ApplicationObjectId">insert objectId here</Item> 
      <Item Key="ClientId">insert appId here</Item> 
      </Metadata> 
     <!-- End of changes --> 
      <CryptographicKeys> 
      <Key Id="issuer_secret" StorageReferenceId="TokenSigningKeyContainer" /> 
      </CryptographicKeys> 
      <IncludeInSso>false</IncludeInSso> 
      <UseTechnicalProfileForSessionManagement ReferenceId="SM-Noop" /> 
     </TechnicalProfile> 
    </ClaimsProvider> 
</ClaimsProviders> 
0

您需要啓用那些屬性(告訴他們)的註冊政策(自定義或沒有)中的一個,並通過對它們設置一個值,政策創建一個帳戶。他們將不會在該租戶和目錄中提供,直到您完成。

0

正如在評論中指出的那樣,您需要在屬性名稱中指定前綴extension_b2c-extensions-app應用程序ID。應用程序ID是一個GUID,但必須包含連字符,例如

extension_93ae98b337124e0aaced3698b59f8acb_Role 

b2c-extension-app ID可以通過在天青AD B2C租戶內的天青門戶選擇All Resources -> App Registrations找到。默認情況下,它顯示My apps的列表;將下拉列表更改爲All apps,然後單擊b2c-extension-app並複製其Application ID

相關問題