|
| 1 | +--- |
| 2 | +title: include file |
| 3 | +description: include file |
| 4 | +services: azure-communication-services |
| 5 | +author: DominikMe |
| 6 | +manager: RezaJooyandeh |
| 7 | + |
| 8 | +ms.service: azure-communication-services |
| 9 | +ms.subservice: azure-communication-services |
| 10 | +ms.date: 08/30/2022 |
| 11 | +ms.topic: include |
| 12 | +ms.custom: include file |
| 13 | +ms.author: domessin |
| 14 | +--- |
| 15 | + |
| 16 | +### Communication User identifier |
| 17 | + |
| 18 | +The `CommunicationUserIdentifier` represents a user identity that was created using the [Identity SDK or REST API](../../../quickstarts/access-tokens.md). It's the only identifier used if your application doesn't use Microsoft Teams interoperability or Telephony features. |
| 19 | + |
| 20 | + |
| 21 | +#### Basic usage |
| 22 | + |
| 23 | +```java |
| 24 | +// at some point you will have created a new user identity in your trusted service |
| 25 | +CommunicationUserIdentifier newUser = identityClient.CreateUser(); |
| 26 | + |
| 27 | +// and then send newUser.getId() down to your client application |
| 28 | +// where you can again create an identifier for the user |
| 29 | +var sameUser = new CommunicationUserIdentifier(newUserId); |
| 30 | +``` |
| 31 | + |
| 32 | +#### API reference |
| 33 | + |
| 34 | +[CommunicationUserIdentifier](https://azure.github.io/azure-sdk-for-android/azure-communication-common/com/azure/android/communication/common/CommunicationUserIdentifier.html) |
| 35 | + |
| 36 | +### Microsoft Teams User identifier |
| 37 | + |
| 38 | +The `MicrosoftTeamsUserIdentifier` represents a Teams user with its Azure AD user object ID. You can retrieve the Azure AD user object ID via the [Microsoft Graph REST API /users](/graph/api/user-get) endpoint from the `id` property in the response. For more information on how to work with Microsoft Graph, try the [Graph Explorer](https://developer.microsoft.com/en-us/graph/graph-explorer?request=users%2F%7Buser-mail%7D&method=GET&version=v1.0&GraphUrl=https://graph.microsoft.com) and look into the [Graph SDK](/graph/sdks/sdks-overview). Alternatively, you can find the ID as the `oid` claim in an [Azure AD ID token](/azure/active-directory/develop/id-tokens#payload-claims) or [Azure AD access token](/azure/active-directory/develop/access-tokens#payload-claims) after your user has signed in and acquired a token. |
| 39 | + |
| 40 | +#### Basic usage |
| 41 | + |
| 42 | +```java |
| 43 | +// get the Teams user's ID from Graph APIs if only the email is known |
| 44 | +var user = await graphClient .users( "[email protected]") |
| 45 | + .buildRequest() |
| 46 | + .get(); |
| 47 | + |
| 48 | +// create an identifier |
| 49 | +var teamsUser = new MicrosoftTeamsUserIdentifier(user.id); |
| 50 | + |
| 51 | +// if you're not operating in the public cloud, you must also set the right Cloud type. |
| 52 | +var gcchTeamsUser = new MicrosoftTeamsUserIdentifier(userId).setCloudEnvironment(CommunicationCloudEnvironment.GCCH); |
| 53 | +``` |
| 54 | + |
| 55 | +#### API reference |
| 56 | + |
| 57 | +[MicrosoftTeamsUserIdentifier](https://azure.github.io/azure-sdk-for-android/azure-communication-common/com/azure/android/communication/common/MicrosoftTeamsUserIdentifier.html) |
| 58 | + |
| 59 | +### Phone Number identifier |
| 60 | + |
| 61 | +The `PhoneNumberIdentifier` represents a phone number. The service assumes that phone numbers are formatted in E.164 format. |
| 62 | + |
| 63 | +#### Basic usage |
| 64 | + |
| 65 | +```java |
| 66 | +// create an identifier |
| 67 | +var phoneNumber = new PhoneNumberIdentifier("+112345556789"); |
| 68 | +``` |
| 69 | + |
| 70 | +#### API reference |
| 71 | + |
| 72 | +[PhoneNumberIdentifier](https://azure.github.io/azure-sdk-for-android/azure-communication-common/com/azure/android/communication/common/PhoneNumberIdentifier.html) |
| 73 | + |
| 74 | +### Unknown identifier |
| 75 | + |
| 76 | +The `UnknownIdentifier` exists for future-proofing and you might encounter it when you are on an old version of the SDK and a new identifier type has been introduced recently. Any unknown identifier from the service will be deserialized to the `UnknownIdentifier` in the SDK. |
| 77 | + |
| 78 | +#### Basic usage |
| 79 | + |
| 80 | +```java |
| 81 | +// create an identifier |
| 82 | +var unknown = new UnknownIdentifier("a raw id that originated in the service"); |
| 83 | +``` |
| 84 | + |
| 85 | +#### API reference |
| 86 | + |
| 87 | +[UnknownIdentifier](https://azure.github.io/azure-sdk-for-android/azure-communication-common/com/azure/android/communication/common/UnknownIdentifier.html) |
| 88 | + |
| 89 | +### How to handle the `CommunicationIdentifier` base class |
| 90 | + |
| 91 | +While you construct identifiers for a concrete type that you pass *into* the SDK, the SDK returns the abstract `CommunicationIdentifier`. You can down-cast back to a concrete type: |
| 92 | + |
| 93 | +```java |
| 94 | +if (communicationIdentifier instanceof CommunicationUserIdentifier) { |
| 95 | + Log.i(tag, "Communication user: " + ((CommunicationUserIdentifier)communicationIdentifier).getId()); |
| 96 | +} |
| 97 | +else if (communicationIdentifier instanceof MicrosoftTeamsUserIdentifier) { |
| 98 | + Log.i(tag, "Teams user: " + ((MicrosoftTeamsUserIdentifier)communicationIdentifier).getUserId()); |
| 99 | +} |
| 100 | +else if (communicationIdentifier instanceof PhoneNumberIdentifier) { |
| 101 | + Log.i(tag, "Phone number: " + ((PhoneNumberIdentifier)communicationIdentifier).getPhoneNumber()); |
| 102 | +} |
| 103 | +else if (communicationIdentifier instanceof UnknownIdentifier) { |
| 104 | + Log.i(tag, "Unkown user: " + ((UnknownIdentifier)communicationIdentifier).getId()); |
| 105 | +} |
| 106 | +else { |
| 107 | + // be careful here whether you want to throw because a new SDK version |
| 108 | + // can introduce new identifier types |
| 109 | +} |
| 110 | +``` |
| 111 | + |
| 112 | +## Raw ID representation |
| 113 | + |
| 114 | +Sometimes you need to serialize an identifier to a flat string. For example, if you want to store the identifier in a database table or if you'd like to use it as a URL parameter. |
| 115 | + |
| 116 | +For that purpose, identifiers have another representation called `RawId`. An identifier can always be translated to its corresponding raw ID, and a valid raw ID can always be converted to an identifier. |
| 117 | + |
| 118 | +Since `azure-communication-common 1.1.0` the SDK helps with the conversion: |
| 119 | + |
| 120 | +```java |
| 121 | +// get an identifier's raw Id |
| 122 | +String rawId = communicationIdentifier.getRawId(); |
| 123 | + |
| 124 | +// create an identifier from a given raw Id |
| 125 | +CommunicationIdentifier identifier = CommunicationIdentifier.fromRawId(rawId); |
| 126 | +``` |
| 127 | + |
| 128 | +An invalid raw ID will just convert to an `UnknownIdentifier` in the SDK and any validation only happens service-side. |
0 commit comments