2016-11-24 15:31:33 +01:00
|
|
|
|
// Copyright (c) Brock Allen & Dominick Baier. All rights reserved.
|
|
|
|
|
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using IdentityServer4.Models;
|
|
|
|
|
|
2017-01-30 11:35:16 +01:00
|
|
|
|
namespace Identity.API.Models.AccountViewModels
|
2016-11-24 15:31:33 +01:00
|
|
|
|
{
|
|
|
|
|
public class ConsentViewModel : ConsentInputModel
|
|
|
|
|
{
|
2017-04-05 09:18:14 -03:00
|
|
|
|
public ConsentViewModel(ConsentInputModel model, string returnUrl, AuthorizationRequest request, Client client, Resources resources)
|
2016-11-24 15:31:33 +01:00
|
|
|
|
{
|
|
|
|
|
RememberConsent = model?.RememberConsent ?? true;
|
|
|
|
|
ScopesConsented = model?.ScopesConsented ?? Enumerable.Empty<string>();
|
|
|
|
|
|
|
|
|
|
ReturnUrl = returnUrl;
|
|
|
|
|
|
|
|
|
|
ClientName = client.ClientName;
|
|
|
|
|
ClientUrl = client.ClientUri;
|
|
|
|
|
ClientLogoUrl = client.LogoUri;
|
|
|
|
|
AllowRememberConsent = client.AllowRememberConsent;
|
|
|
|
|
|
2017-04-05 09:18:14 -03:00
|
|
|
|
IdentityScopes = resources.IdentityResources.Select(x => new ScopeViewModel(x, ScopesConsented.Contains(x.Name) || model == null)).ToArray();
|
|
|
|
|
ResourceScopes = resources.ApiResources.SelectMany(x => x.Scopes).Select(x => new ScopeViewModel(x, ScopesConsented.Contains(x.Name) || model == null)).ToArray();
|
2016-11-24 15:31:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string ClientName { get; set; }
|
|
|
|
|
public string ClientUrl { get; set; }
|
|
|
|
|
public string ClientLogoUrl { get; set; }
|
|
|
|
|
public bool AllowRememberConsent { get; set; }
|
|
|
|
|
|
|
|
|
|
public IEnumerable<ScopeViewModel> IdentityScopes { get; set; }
|
|
|
|
|
public IEnumerable<ScopeViewModel> ResourceScopes { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class ScopeViewModel
|
|
|
|
|
{
|
|
|
|
|
public ScopeViewModel(Scope scope, bool check)
|
|
|
|
|
{
|
|
|
|
|
Name = scope.Name;
|
|
|
|
|
DisplayName = scope.DisplayName;
|
|
|
|
|
Description = scope.Description;
|
|
|
|
|
Emphasize = scope.Emphasize;
|
|
|
|
|
Required = scope.Required;
|
|
|
|
|
Checked = check || scope.Required;
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-05 09:18:14 -03:00
|
|
|
|
public ScopeViewModel(IdentityResource identity, bool check)
|
|
|
|
|
{
|
|
|
|
|
Name = identity.Name;
|
|
|
|
|
DisplayName = identity.DisplayName;
|
|
|
|
|
Description = identity.Description;
|
|
|
|
|
Emphasize = identity.Emphasize;
|
|
|
|
|
Required = identity.Required;
|
|
|
|
|
Checked = check || identity.Required;
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 15:31:33 +01:00
|
|
|
|
public string Name { get; set; }
|
|
|
|
|
public string DisplayName { get; set; }
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public bool Emphasize { get; set; }
|
|
|
|
|
public bool Required { get; set; }
|
|
|
|
|
public bool Checked { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|