コード例 #1
0
    public async Task <ApplicationInfo> GetAsync(string id)
    {
        if (id == null)
        {
            throw new ArgumentNullException(nameof(id));
        }

        var entity = await _manager.FindByIdAsync(id);

        return(entity != null?ToInfo(entity) : null);
    }
コード例 #2
0
        public async Task CreateAsync(ApplicationClient applicationClient, CancellationToken cancellationToken)
        {
            if (applicationClient == null)
            {
                throw new ArgumentNullException(nameof(applicationClient));
            }

            var entity = await _applicationManager.FindByIdAsync(applicationClient.Id.ToString(), cancellationToken);

            if (entity == null)
            {
                await _applicationManager.CreateAsync(applicationClient, applicationClient.ClientSecret,
                                                      cancellationToken);
            }
        }
コード例 #3
0
        public async Task <IActionResult> Edit(string id, string returnUrl = null)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOpenIdApplications))
            {
                return(Unauthorized());
            }

            var openIdSettings = await _openIdService.GetOpenIdSettingsAsync();

            if (!_openIdService.IsValidOpenIdSettings(openIdSettings))
            {
                _notifier.Warning(H["OpenID Connect settings are not properly configured."]);
            }

            var application = await _applicationManager.FindByIdAsync(id, HttpContext.RequestAborted);

            if (application == null)
            {
                return(NotFound());
            }

            var model = new EditOpenIdApplicationViewModel()
            {
                Id                = id,
                DisplayName       = application.DisplayName,
                RedirectUri       = application.RedirectUri,
                LogoutRedirectUri = application.LogoutRedirectUri,
                ClientId          = application.ClientId,
                Type              = application.Type,
                SkipConsent       = application.SkipConsent,
                RoleEntries       = (await _roleProvider.GetRoleNamesAsync())
                                    .Select(r => new RoleEntry()
                {
                    Name     = r,
                    Selected = application.RoleNames.Contains(r),
                }).ToList(),
                AllowAuthorizationCodeFlow = application.AllowAuthorizationCodeFlow,
                AllowClientCredentialsFlow = application.AllowClientCredentialsFlow,
                AllowImplicitFlow          = application.AllowImplicitFlow,
                AllowPasswordFlow          = application.AllowPasswordFlow,
                AllowRefreshTokenFlow      = application.AllowRefreshTokenFlow
            };

            ViewData["OpenIdSettings"] = openIdSettings;
            ViewData["ReturnUrl"]      = returnUrl;
            return(View(model));
        }
コード例 #4
0
        public async Task SeedAsync()
        {
            // Create the Db if it doesn't exist
            _dbContext.Database.EnsureCreated();
            // Create default Application
            if (await _applicationManager.FindByIdAsync("ECERP", CancellationToken.None) == null)
            {
                await CreateApplication();
            }
            // Create default Users
            if (await _dbContext.Users.CountAsync() == 0)
            {
                await CreateUsersAsync();
            }

#if DEBUG
            // Create default Companies
            if (!_dbContext.Companies.Any())
            {
                CreateCompanies();
            }

            // Create default cities
            if (!_dbContext.Cities.Any())
            {
                CreateCities();
            }

            // Create default Suppliers
            if (!_dbContext.Suppliers.Any())
            {
                CreateSuppliers();
            }

            // Create default Product Categories
            if (!_dbContext.ProductCategories.Any())
            {
                CreateProductCategories();
            }

            // Create default Products
            if (!_dbContext.Products.Any())
            {
                CreateProducts();
            }
#endif
        }
コード例 #5
0
        public async Task <Maybe <Client> > GetById(ClientId id, CancellationToken cancellationToken = default(CancellationToken))
        {
            cancellationToken.ThrowIfCancellationRequested();
            var result = await _applicationManager.FindByIdAsync(id.Id, cancellationToken);

            return(await Task.Factory.StartNew(() =>
            {
                var client = new Client()
                {
                    Id = new ClientId(result.Id),
                    Active = result.Active,
                    AllowedOrigin = result.AllowedOrigin,
                    ApplicationType = result.Type,
                    Key = result.ClientId,
                    Name = result.DisplayName,
                    RedirectUri = result.RedirectUri,
                    Secret = result.ClientSecret,
                    LogoutRedirectUri = result.LogoutRedirectUri
                };
                return client;
            }, cancellationToken));
        }
コード例 #6
0
        public async Task ExecuteAsync(RecipeExecutionContext context)
        {
            if (!string.Equals(context.Name, "OpenIdApplication", StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var model       = context.Step.ToObject <OpenIdApplicationStepModel>();
            var application = new OpenIdApplication();

            if (model.Id != 0)
            {
                application = await _applicationManager.FindByIdAsync(model.Id.ToString(), CancellationToken.None);
            }
            application.ClientId    = model.ClientId;
            application.DisplayName = model.DisplayName;
            application.AllowAuthorizationCodeFlow = model.AllowAuthorizationCodeFlow;
            application.AllowClientCredentialsFlow = model.AllowClientCredentialsFlow;
            application.AllowHybridFlow            = model.AllowHybridFlow;
            application.AllowImplicitFlow          = model.AllowImplicitFlow;
            application.AllowPasswordFlow          = model.AllowPasswordFlow;
            application.AllowRefreshTokenFlow      = model.AllowRefreshTokenFlow;
            application.LogoutRedirectUri          = model.LogoutRedirectUri;
            application.RedirectUri = model.RedirectUri;
            application.SkipConsent = model.SkipConsent;
            application.RoleNames   = model.RoleNames;
            application.Type        = model.Type;

            if (model.Type == ClientType.Confidential)
            {
                await _applicationManager.CreateAsync(application, model.ClientSecret, CancellationToken.None);
            }

            else
            {
                await _applicationManager.CreateAsync(application, CancellationToken.None);
            }
        }