internal static CommunicationUserIdentifierAndToken DeserializeCommunicationUserIdentifierAndToken(JsonElement element)
        {
            CommunicationIdentity identity = default;
            Optional <CommunicationIdentityAccessToken> accessToken = default;

            foreach (var property in element.EnumerateObject())
            {
                if (property.NameEquals("identity"))
                {
                    identity = CommunicationIdentity.DeserializeCommunicationIdentity(property.Value);
                    continue;
                }
                if (property.NameEquals("accessToken"))
                {
                    if (property.Value.ValueKind == JsonValueKind.Null)
                    {
                        property.ThrowNonNullablePropertyIsNull();
                        continue;
                    }
                    accessToken = CommunicationIdentityAccessToken.DeserializeCommunicationIdentityAccessToken(property.Value);
                    continue;
                }
            }
            return(new CommunicationUserIdentifierAndToken(identity, accessToken.Value));
        }
        internal CommunicationUserIdentifierAndToken(CommunicationIdentity identity, CommunicationIdentityAccessToken accessToken)
        {
            if (identity == null)
            {
                throw new ArgumentNullException(nameof(identity));
            }

            Identity            = identity;
            InternalAccessToken = accessToken;
            User         = new CommunicationUserIdentifier(identity.Id);
            _accessToken = accessToken is null ? null : new AccessToken(accessToken.Token, accessToken.ExpiresOn);
        }
Ejemplo n.º 3
0
 CreateUserWithToken(IEnumerable <CommunicationTokenScope> scopes, CancellationToken cancellationToken = default)
 {
     using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(CommunicationIdentityClient)}.{nameof(CreateUserWithToken)}");
     scope.Start();
     try
     {
         Response <CommunicationIdentityAccessTokenResult> response = RestClient.Create(scopes, cancellationToken);
         var id = response.Value.Identity.Id;
         CommunicationIdentityAccessToken rawToken = response.Value.AccessToken;
         return(Response.FromValue((new CommunicationUserIdentifier(id), new AccessToken(rawToken.Token, rawToken.ExpiresOn)), response.GetRawResponse()));
     }
     catch (Exception ex)
     {
         scope.Failed(ex);
         throw;
     }
 }