Пример #1
0
        public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
        {
            var now     = DateTime.UtcNow;
            var userId  = session.UserAuthId;
            var apiKeys = new List <ApiKey>();

            foreach (var env in apiKeyProvider.Environments)
            {
                foreach (var keyType in apiKeyProvider.KeyTypes)
                {
                    var key = apiKeyProvider.CreateApiKeyFn(env, keyType, apiKeyProvider.KeySizeBytes);

                    var apiKey = new ApiKey
                    {
                        UserAuthId  = userId,
                        Environment = env,
                        KeyType     = keyType,
                        Key         = key,
                        CreatedDate = now,
                    };

                    if (apiKeyProvider.ApiKeyFilterFn != null)
                    {
                        apiKeyProvider.ApiKeyFilterFn(apiKey);
                    }

                    apiKeys.Add(apiKey);
                }
            }

            using (var db = HostContext.AppHost.GetDbConnection(httpReq))
            {
                db.InsertAll(apiKeys);
            }
        }
Пример #2
0
        public override void OnRegistered(IRequest httpReq, IAuthSession session, IServiceBase registrationService)
        {
            var now     = DateTime.UtcNow;
            var userId  = session.UserAuthId;
            var apiKeys = new List <ApiKey>();

            foreach (var env in apiKeyProvider.Environments)
            {
                foreach (var keyType in apiKeyProvider.KeyTypes)
                {
                    var key = apiKeyProvider.CreateApiKeyFn(env, keyType, apiKeyProvider.KeySizeBytes);

                    var apiKey = new ApiKey
                    {
                        UserAuthId  = userId,
                        Environment = env,
                        KeyType     = keyType,
                        Id          = key,
                        CreatedDate = now,
                    };

                    if (apiKeyProvider.ApiKeyFilterFn != null)
                    {
                        apiKeyProvider.ApiKeyFilterFn(apiKey);
                    }

                    apiKeys.Add(apiKey);
                }
            }

            var authRepo = (IManageApiKeys)httpReq.TryResolve <IAuthRepository>().AsUserAuthRepository(httpReq);

            authRepo.StoreAll(apiKeys);
        }