예제 #1
0
        static private KZUser createUser(RequestTokenResult userToken, RequestTokenResult serviceBusToken, RequestTokenResult marketplaceToken)
        {
            var tokenClaims = WebUtility.UrlDecode(userToken.Token)
                              .Split('&')
                              .Select(c =>
            {
                var pair = c.Split('=');
                return(new { Key = pair[0], Value = pair[1] });
            })
                              .GroupBy((p) => p.Key, (k, e) => new { Key = k, Value = e.Select((p) => p.Value).ToArray() })
                              .ToDictionary(p => p.Key, p => p.Value);

            var tokenClaimsByName = tokenClaims.Select(p =>
            {
                var key = p.Key;
                var indexOfClaimKeyword = p.Key.IndexOf("/claims/");
                if (indexOfClaimKeyword > -1)
                {
                    key = p.Key.Substring(indexOfClaimKeyword + "/claims/".Length);
                }
                return(new { Key = key, Value = p.Value });
            })
                                    .GroupBy((p) => p.Key, (k, e) => new { Key = k, Value = e.Select((p) => p.Value).Aggregate((x, y) => x.Concat(y).ToArray()) })
                                    .ToDictionary(p => p.Key, p => p.Value);

            return(new KZUser
            {
                TokenApplication = Token.Create(userToken),
                TokenMarketplace = Token.Create(marketplaceToken),
                TokenServiceBus = Token.Create(serviceBusToken),
                Claims = tokenClaims,
                ClaimsByName = tokenClaimsByName,
                Roles = tokenClaims.ContainsKey("role") ? tokenClaims["role"] : new string[0]
            });
        }
예제 #2
0
        static private KZUser createUser(RequestTokenResult userToken, RequestTokenResult serviceBusToken, RequestTokenResult marketplaceToken)
        {
            var tokenClaims = WebUtility.UrlDecode(userToken.Token)
                .Split('&')
                .Select(c =>
                {
                    var pair = c.Split('=');
                    return new { Key = pair[0], Value = pair[1] };
                })
                .GroupBy((p) => p.Key, (k, e) => new { Key = k, Value = e.Select((p) => p.Value).ToArray() })
                .ToDictionary(p => p.Key, p => p.Value);

            var tokenClaimsByName = tokenClaims.Select(p =>
                {
                    var key = p.Key;
                    var indexOfClaimKeyword = p.Key.IndexOf("/claims/");
                    if (indexOfClaimKeyword > -1)
                    {
                        key = p.Key.Substring(indexOfClaimKeyword + "/claims/".Length);
                    }
                    return new { Key = key, Value = p.Value };
                })
                .GroupBy((p) => p.Key, (k, e) => new { Key = k, Value = e.Select((p) => p.Value).Aggregate((x,y)=>x.Concat(y).ToArray()) })
                .ToDictionary(p => p.Key, p => p.Value);

            return new KZUser
            {
                TokenApplication = Token.Create(userToken),
                TokenMarketplace = Token.Create(marketplaceToken),
                TokenServiceBus = Token.Create(serviceBusToken),
                Claims = tokenClaims,
                ClaimsByName = tokenClaimsByName,
                Roles = tokenClaims.ContainsKey("role") ? tokenClaims["role"] : new string[0]
            };
        }    
예제 #3
0
        static internal Token Create(RequestTokenResult request)
        {
            if (request == null) return null;

            return new Token {
                Value = request.Token,
                Expiration = request.ExpirationTime.HasValue ? request.ExpirationTime.Value : DateTime.MaxValue
            };
        }
예제 #4
0
파일: Token.cs 프로젝트: kidozen/kido-win
        static internal Token Create(RequestTokenResult request)
        {
            if (request == null)
            {
                return(null);
            }

            return(new Token {
                Value = request.Token,
                Expiration = request.ExpirationTime.HasValue ? request.ExpirationTime.Value : DateTime.MaxValue
            });
        }
예제 #5
0
        static internal async Task <KZUser> Authenticate(IdentityProviderConfig config)
        {
            try
            {
                var ipToken = await config.instance.RequestToken(new Uri(config.ipEndpoint), config.authServiceScope);

                var kzTokenUser = await RequestKidoTokenAsync(config.authServiceEndpoint, config.applicationScope, ipToken.Token);

                var kzMarketplaceTokenUser = await RequestKidoTokenAsync(config.authServiceEndpoint, config.marketplaceScope, ipToken.Token);

                RequestTokenResult kzTokenSB = null;
                //if (!string.IsNullOrWhiteSpace(config.serviceBusIpScope))
                //{
                //    ipToken = await config.instance.RequestToken(new Uri(config.ipEndpoint), config.serviceBusIpScope);
                //    kzTokenSB = await RequestKidoTokenAsync(config.serviceBusEndpoint, config.serviceBusScope, ipToken.Token);
                //}

                return(createUser(kzTokenUser, kzTokenSB, kzMarketplaceTokenUser));
            }
            catch (Exception e)
            {
                throw new Exception("User could not be authenticated.", e);
            }
        }