Ejemplo n.º 1
0
        public async Task <string> GenerateClientAccessTokenAsync(string hubName = null, IEnumerable <Claim> claims = null, TimeSpan?lifetime = null)
        {
            var audience = $"{_endpoint}/{ClientPath}";
            await _accessKey.AuthorizedTask;

            return(AuthUtility.GenerateAccessToken(_accessKey, audience, claims, lifetime ?? _accessTokenLifetime, _algorithm));
        }
        public string GenerateServerAccessToken(string hubName, string userId, TimeSpan?lifetime = null)
        {
            IEnumerable <Claim> claims = null;

            if (userId != null)
            {
                claims = new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, userId)
                };
            }

            var audience = $"{_endpoint}/{ServerPath}/?hub={GetPrefixedHubName(_appName, hubName)}";

            return(AuthUtility.GenerateAccessToken(_accessKey, audience, claims, lifetime ?? _accessTokenLifetime, _algorithm));
        }
        public void TestAccessTokenTooLongThrowsException()
        {
            var claims    = GenerateClaims(100);
            var exception = Assert.Throws <AzureSignalRAccessTokenTooLongException>(() => AuthUtility.GenerateAccessToken(new AccessKey(SigningKey), Audience, claims, DefaultLifetime, AccessTokenAlgorithm.HS256));

            Assert.Equal("AccessToken must not be longer than 4K.", exception.Message);
        }
 public string Generate(string audience, TimeSpan?lifetime = null)
 {
     return(AuthUtility.GenerateAccessToken(_accessKey, audience, _claims, lifetime ?? Constants.DefaultAccessTokenLifetime, AccessTokenAlgorithm.HS256));
 }