コード例 #1
0
        public string GenerateClientAccessToken(string hubName, string userId = null, IList <Claim> claims = null, TimeSpan?lifeTime = null)
        {
            var claimsWithUserId = new List <Claim>();

            if (userId != null)
            {
                claimsWithUserId.Add(new Claim(ClaimTypes.NameIdentifier, userId));
            }
            ;
            if (claims != null)
            {
                claimsWithUserId.AddRange(claims);
            }
            return(_endpointProvider.GenerateClientAccessTokenAsync(hubName, claimsWithUserId, lifeTime).Result);
        }
コード例 #2
0
 private async Task GenerateClientAccessTokenAsync(
     IServiceEndpointProvider provider,
     HostContext context,
     string url,
     IEnumerable <Claim> claims)
 {
     try
     {
         var accessToken = await provider.GenerateClientAccessTokenAsync(null, claims);
         await SendJsonResponse(context, GetRedirectNegotiateResponse(url, accessToken));
     }
     catch (AzureSignalRAccessTokenTooLongException ex)
     {
         Log.NegotiateFailed(_logger, ex.Message);
         context.Response.StatusCode = 413;
         await context.Response.End(ex.Message);
     }
 }
コード例 #3
0
        public string GenerateClientAccessToken(string hubName, string userId = null, IList <Claim> claims = null, TimeSpan?lifeTime = null)
        {
            if (_endpointProvider == null)
            {
                throw new InvalidOperationException(EmptyConnectionStringMessage);
            }
            var claimsWithUserId = new List <Claim>();

            if (userId != null)
            {
                claimsWithUserId.Add(new Claim(ClaimTypes.NameIdentifier, userId));
            }
            ;
            if (claims != null)
            {
                claimsWithUserId.AddRange(claims);
            }
            return(_endpointProvider.GenerateClientAccessTokenAsync(hubName, claimsWithUserId, lifeTime).Result);
        }