Ejemplo n.º 1
0
        private static void BuildToken(TokenBuilder tokenBuilder)
        {
            if (!string.IsNullOrEmpty(Uri))
            {
                tokenBuilder.WithUri(Uri);
            }

            if (!string.IsNullOrEmpty(ExpiresAt))
            {
                tokenBuilder.ExpiresAt(DateTimeOffset.FromUnixTimeMilliseconds(Convert.ToInt64(ExpiresAt, 10)).UtcDateTime);
            }
            else
            {
                long expirationInSeconds = DEFAULT_EXPIRATION_IN_SECONDS;

                if (!string.IsNullOrEmpty(ExpiresInSeconds))
                {
                    expirationInSeconds = Convert.ToInt64(ExpiresInSeconds, 10);
                }

                tokenBuilder.ExpiresInSeconds(expirationInSeconds);
            }

            if (AuthenticationOnly != null)
            {
                tokenBuilder.ForAuthenticationOnly();
            }

            if (StreamingOnly != null)
            {
                tokenBuilder.ForStreamingOnly();
            }

            if (PublishingOnly != null)
            {
                tokenBuilder.ForPublishingOnly();
            }

            if (!string.IsNullOrEmpty(Capability))
            {
                foreach (string capability in Capability.Split(","))
                {
                    tokenBuilder.WithCapability(capability.Trim());
                }
            }

            if (!string.IsNullOrEmpty(SessionId))
            {
                tokenBuilder.ForSession(SessionId);
            }

            if (!string.IsNullOrEmpty(RemoteAddress))
            {
                tokenBuilder.ForRemoteAddress(RemoteAddress);
            }

            if (!string.IsNullOrEmpty(OriginStreamId))
            {
                tokenBuilder.ForOriginStream(OriginStreamId);
            }

            if (!string.IsNullOrEmpty(Channel))
            {
                tokenBuilder.ForChannel(Channel);
            }

            if (!string.IsNullOrEmpty(ChannelAlias))
            {
                tokenBuilder.ForChannelAlias(ChannelAlias);
            }

            if (!string.IsNullOrEmpty(Room))
            {
                tokenBuilder.ForRoom(Room);
            }

            if (!string.IsNullOrEmpty(RoomAlias))
            {
                tokenBuilder.ForRoomAlias(RoomAlias);
            }

            if (!string.IsNullOrEmpty(Tag))
            {
                tokenBuilder.ForTag(Tag);
            }

            if (!string.IsNullOrEmpty(ApplyTag))
            {
                tokenBuilder.ApplyTag(ApplyTag);
            }
        }