Beispiel #1
0
        public static Task <IdentityResult> GenerateClientSecretAsync(this UserManager <IdentityUser> userManager, IdentityUser user)
        {
            var claims = new List <Claim> {
                new Claim(SquidexClaimTypes.ClientSecret, RandomHash.New())
            };

            return(userManager.SyncClaimsAsync(user, claims));
        }
Beispiel #2
0
        private async Task GenerateClientSecretAsync(string id)
        {
            var update = new UserValues {
                ClientSecret = RandomHash.New()
            };

            await userService.UpdateAsync(id, update);
        }
Beispiel #3
0
        private async Task GenerateClientSecretAsync(string id)
        {
            var update = new UserValues {
                ClientSecret = RandomHash.New()
            };

            await userService.UpdateAsync(id, update, ct : HttpContext.RequestAborted);
        }
Beispiel #4
0
        public static Task <IdentityResult> GenerateClientSecretAsync(this UserManager <IdentityUser> userManager, IdentityUser user)
        {
            var update = new UserValues
            {
                ClientSecret = RandomHash.New()
            };

            return(update.SyncClaims(userManager, user));
        }
Beispiel #5
0
        private async Task GenerateClientSecretAsync(string id,
                                                     CancellationToken ct)
        {
            var update = new UserValues {
                ClientSecret = RandomHash.New()
            };

            await userService.UpdateAsync(id, update, ct : ct);
        }
Beispiel #6
0
        public static User Create(string appId, string userId)
        {
            var user = new User {
                AppId = appId, Id = userId
            };

            user.ApiKey = RandomHash.New();

            return(user);
        }
Beispiel #7
0
        public Task ExecuteAsync(User user, IServiceProvider serviceProvider, CancellationToken ct)
        {
            Validate <Validator> .It(this);

            if (FullName != null)
            {
                user.FullName = FullName;
            }

            if (EmailAddress != null)
            {
                user.EmailAddress = EmailAddress;
            }

            if (PhoneNumber != null)
            {
                user.PhoneNumber = PhoneNumber;
            }

            if (PreferredLanguage != null)
            {
                user.PreferredLanguage = PreferredLanguage;
            }

            if (PreferredTimezone != null)
            {
                user.PreferredTimezone = PreferredTimezone;
            }

            if (RequiresWhitelistedTopics != null)
            {
                user.RequiresWhitelistedTopics = RequiresWhitelistedTopics.Value;
            }

            if (Settings != null)
            {
                user.Settings = Settings;
            }

            if (string.IsNullOrWhiteSpace(user.ApiKey))
            {
                user.ApiKey = RandomHash.New();
            }

            return(Task.CompletedTask);
        }
 public AttachClient()
 {
     Secret = RandomHash.New();
 }
Beispiel #9
0
        public async Task ExecuteAsync(App app, IServiceProvider serviceProvider, CancellationToken ct)
        {
            Validate <Validator> .It(this);

            if (!string.Equals(EmailAddress, app.EmailAddress, StringComparison.OrdinalIgnoreCase))
            {
                var emailServer = serviceProvider.GetRequiredService <IEmailServer>() !;

                if (!string.IsNullOrWhiteSpace(app.EmailAddress))
                {
                    await emailServer.RemoveEmailAddressAsync(app.EmailAddress, ct);
                }

                if (!string.IsNullOrWhiteSpace(EmailAddress))
                {
                    var appRepository = serviceProvider.GetRequiredService <IAppRepository>();

                    var(existing, _) = await appRepository.GetByEmailAddressAsync(EmailAddress, ct);

                    if (existing != null)
                    {
                        throw new DomainException("The email address is already in use by another app.");
                    }

                    var status = await emailServer.AddEmailAddressAsync(EmailAddress, ct);

                    app.EmailVerificationStatus = status;
                }

                app.EmailAddress = EmailAddress ?? string.Empty;
            }

            if (Name != null)
            {
                app.Name = Name;
            }

            if (EmailName != null)
            {
                app.EmailName = EmailName;
            }

            if (FirebaseProject != null)
            {
                app.FirebaseProject = FirebaseProject;
            }

            if (FirebaseCredential != null)
            {
                app.FirebaseCredential = FirebaseCredential;
            }

            if (WebhookUrl != null)
            {
                app.WebhookUrl = WebhookUrl;
            }

            if (ConfirmUrl != null)
            {
                app.ConfirmUrl = ConfirmUrl;
            }

            if (AllowEmail != null)
            {
                app.AllowEmail = AllowEmail.Value;
            }

            if (AllowSms != null)
            {
                app.AllowSms = AllowSms.Value;
            }

            if (Languages != null)
            {
                app.Languages = Languages;
            }

            if (app.ApiKeys.Count == 0)
            {
                app.ApiKeys[RandomHash.New()] = NotifoRoles.AppAdmin;
                app.ApiKeys[RandomHash.New()] = NotifoRoles.AppAdmin;
                app.ApiKeys[RandomHash.New()] = NotifoRoles.AppWebManager;
                app.ApiKeys[RandomHash.New()] = NotifoRoles.AppWebManager;
            }

            if (app.Contributors.Count == 0 && !string.IsNullOrWhiteSpace(UserId))
            {
                app.Contributors[UserId] = NotifoRoles.AppOwner;
            }
        }
Beispiel #10
0
 public Task <string> GenerateUserTokenAsync(string appId, string userId)
 {
     return(Task.FromResult(RandomHash.New()));
 }
Beispiel #11
0
        public void Configure(OpenIddictServerOptions options)
        {
            var collection = database.GetCollection <MongoDbKey>("Identity_Key6");

            var key = collection.Find(x => x.Id == "Default").FirstOrDefault();

            RsaSecurityKey securityKey;

            if (key == null)
            {
                securityKey = new RsaSecurityKey(RSA.Create(2048))
                {
                    KeyId = RandomHash.New()
                };

                key = new MongoDbKey {
                    Id = "Default", Key = securityKey.KeyId
                };

                if (securityKey.Rsa != null)
                {
                    var parameters = securityKey.Rsa.ExportParameters(true);

                    key.Parameters = MongoDbKeyParameters.Create(parameters);
                }
                else
                {
                    key.Parameters = MongoDbKeyParameters.Create(securityKey.Parameters);
                }

                try
                {
                    collection.InsertOne(key);
                }
                catch (MongoWriteException ex)
                {
                    if (ex.WriteError?.Category == ServerErrorCategory.DuplicateKey)
                    {
                        key = collection.Find(x => x.Id == "Default").FirstOrDefault();
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            if (key == null)
            {
                throw new InvalidOperationException("Cannot read key.");
            }

            securityKey = new RsaSecurityKey(key.Parameters.ToParameters())
            {
                KeyId = key.Key
            };

            options.SigningCredentials.Add(
                new SigningCredentials(securityKey,
                                       SecurityAlgorithms.RsaSha256));

            options.EncryptionCredentials.Add(new EncryptingCredentials(securityKey,
                                                                        SecurityAlgorithms.RsaOAEP,
                                                                        SecurityAlgorithms.Aes256CbcHmacSha512));
        }