コード例 #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenId"/> class.
 /// </summary>
 public OpenId(string prefix = DefaultPrefix)
 {
     Name        = $"{prefix}{IdentityServerConstants.StandardScopes.OpenId}";
     DisplayName = $"{prefix} Your user identifier";
     Required    = true;
     UserClaims.Add(JwtClaimTypes.Subject);
 }
コード例 #2
0
 public SecurityStampResource()
 {
     Name        = "security_stamp";
     DisplayName = "ASP NET Identity security stamp";
     Required    = true;
     UserClaims.Add(ScopeName);
 }
コード例 #3
0
 public Permissions(IStringLocalizer <AppResources> localizer)
 {
     Name        = Scope;
     DisplayName = localizer.GetString("Permissions");
     Required    = true;
     UserClaims.Add(Scope);
 }
コード例 #4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="OpenId"/> class.
 /// </summary>
 public OpenId()
 {
     Name        = IdentityServerConstants.StandardScopes.OpenId;
     DisplayName = "Your user identifier";
     Required    = true;
     UserClaims.Add(JwtClaimTypes.Subject);
 }
コード例 #5
0
 public virtual void AddUserClaim([NotNull] string type)
 {
     UserClaims.Add(new ApiResourceClaim()
     {
         ApiResourceId = Id,
         Type          = type
     });
 }
コード例 #6
0
ファイル: ApiScope.cs プロジェクト: majidbigdeli/septa.Auth
 public virtual void AddUserClaim([NotNull] string type)
 {
     UserClaims.Add(new ApiScopeClaim()
     {
         ScopeId = Id,
         Type    = type
     });
 }
コード例 #7
0
 public ProfileWithRoleIdentityResource()
 {
     UserClaims.Add(JwtClaimTypes.Name);
     UserClaims.Add(JwtClaimTypes.Subject);
     UserClaims.Add(JwtClaimTypes.WebSite);
     UserClaims.Add(JwtClaimTypes.Email);
     UserClaims.Add(JwtClaimTypes.Role);
 }
コード例 #8
0
 public Manager(string username) : base(username)
 {
     UserClaims.Add(new Claim {
         Name = "ViewEmployee", Value = "true"
     });
     UserClaims.Add(new Claim {
         Name = "EditEmployee", Value = "true"
     });
 }
コード例 #9
0
ファイル: Administrator.cs プロジェクト: DSMP/AuthExampleTest
 public Administrator(string username) : base(username)
 {
     UserClaims.Add(new Claim {
         Name = "ManageUser", Value = "true"
     });
     UserClaims.Add(new Claim {
         Name = "ManagePermission", Value = "true"
     });
 }
コード例 #10
0
 public override Task AddClaimsAsync(User user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default)
 {
     ThrowIfDisposed();
     user.CheakArgument();
     claims.CheakArgument();
     foreach (var claim in claims)
     {
         UserClaims.Add(CreateUserClaim(user, claim));
     }
     return(Task.CompletedTask);
 }
コード例 #11
0
 /// <inheritdoc/>
 public override async Task AddClaimsAsync(TUser user, IEnumerable <Claim> claims, CancellationToken cancellationToken)
 {
     ThrowIfDisposed();
     user.ThrowIfNull(nameof(user));
     claims.ThrowIfNull(nameof(claims));
     UserClaims ??= (await UserClaimsTable.GetClaimsAsync(user.Id)).ToList();
     foreach (var claim in claims)
     {
         UserClaims.Add(CreateUserClaim(user, claim));
     }
 }
コード例 #12
0
        public IdentityResource(string name, string displayName, IEnumerable <string> claimTypes)
        {
            Name        = name;
            DisplayName = displayName;

            if (claimTypes != null && claimTypes.Count() != 0)
            {
                foreach (var type in claimTypes)
                {
                    UserClaims.Add(type);
                }
            }
        }
コード例 #13
0
 public MyIdentityResource()
 {
     Name        = "customscope";
     DisplayName = "Custom identity resource";
     Emphasize   = true;
     UserClaims.Add("toto");
     UserClaims.Add(ClaimTypes.Role);
     UserClaims.Add(ClaimTypes.Name);
     UserClaims.Add(ClaimTypes.NameIdentifier);
     UserClaims.Add(ClaimTypes.WindowsAccountName);
     UserClaims.Add(ClaimTypes.GroupSid);
     UserClaims.Add(ClaimTypes.Email);
 }
コード例 #14
0
        public ApiResource(string name, string displayName, IEnumerable <string> claimTypes)
        {
            Name        = name;
            DisplayName = displayName;

            Scopes.Add(new Scope(name, displayName));

            if (claimTypes != null && claimTypes.Count() != 0)
            {
                foreach (var type in claimTypes)
                {
                    UserClaims.Add(type);
                }
            }
        }
コード例 #15
0
ファイル: UserStore.cs プロジェクト: china-live/OCore
 /// <summary>
 /// Adds the <paramref name="claims"/> given to the specified <paramref name="user"/>.
 /// </summary>
 /// <param name="user">The user to add the claim to.</param>
 /// <param name="claims">The claim to add to the user.</param>
 /// <param name="cancellationToken">The <see cref="CancellationToken"/> used to propagate notifications that the operation should be canceled.</param>
 /// <returns>The <see cref="Task"/> that represents the asynchronous operation.</returns>
 public override Task AddClaimsAsync(User user, IEnumerable <Claim> claims, CancellationToken cancellationToken = default(CancellationToken))
 {
     ThrowIfDisposed();
     if (user == null)
     {
         throw new ArgumentNullException(nameof(user));
     }
     if (claims == null)
     {
         throw new ArgumentNullException(nameof(claims));
     }
     foreach (var claim in claims)
     {
         UserClaims.Add(CreateUserClaim(user, claim));
     }
     return(Task.FromResult(false));
 }
コード例 #16
0
        public ApiResource(string scopeName, string displayName, IEnumerable <string> userClaimTypes)
        {
            if (scopeName.IsMissing())
            {
                throw new ArgumentNullException(nameof(scopeName));
            }

            Name = scopeName;
            Scopes.Add(new Scope(scopeName, displayName));

            if (!userClaimTypes.IsNullOrEmpty())
            {
                foreach (var type in userClaimTypes)
                {
                    UserClaims.Add(new UserClaim(type));
                }
            }
        }
コード例 #17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ApiScope"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="userClaims">List of associated user claims that should be included when this resource is requested.</param>
        /// <exception cref="System.ArgumentNullException">name</exception>
        public ApiScope(string name, string displayName, IEnumerable <string> userClaims)
        {
            if (name.IsMissing())
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name        = name;
            DisplayName = displayName;

            if (!userClaims.IsNullOrEmpty())
            {
                foreach (var type in userClaims)
                {
                    UserClaims.Add(type);
                }
            }
        }
コード例 #18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="IdentityResource"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="displayName">The display name.</param>
        /// <param name="userClaims">List of associated user claims that should be included when this resource is requested.</param>
        /// <exception cref="System.ArgumentNullException">name</exception>
        /// <exception cref="System.ArgumentException">Must provide at least one claim type - claimTypes</exception>
        public IdentityResource(string name, string displayName, IEnumerable <string> userClaims)
        {
            if (name.IsMissing())
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (userClaims.IsNullOrEmpty())
            {
                throw new ArgumentException("Must provide at least one claim type", nameof(userClaims));
            }

            Name        = name;
            DisplayName = displayName;

            foreach (var type in userClaims)
            {
                UserClaims.Add(type);
            }
        }
コード例 #19
0
        public IdentityResourceViewModel(string name, string displayName, IEnumerable <string> claimTypes)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (claimTypes.IsNullOrEmpty())
            {
                throw new ArgumentException("Must provide at least one claim type", nameof(claimTypes));
            }

            Name        = name;
            DisplayName = displayName;

            foreach (var type in claimTypes)
            {
                UserClaims.Add(type);
            }
        }
コード例 #20
0
        private UserEntity CreateUser(int id, string password, string userName, string inGameName, UserRole role)
        {
            var passwordHash = PasswordHasher.HashPassword(null, password);

            var user = new UserEntity
            {
                UserName            = userName,
                PasswordHash        = passwordHash,
                SecurityStamp       = NewSecurityStamp(),
                InGameName          = inGameName,
                IsDeleted           = false,
                CreationDateUtc     = DateTime.UtcNow,
                ModificationDateUtc = DateTime.UtcNow
            };

            UserClaims ??= new List <UserClaimEntity>();

            UserClaims.Add(CreateUserClaim(user, AppClaimTypes.Role, role.ToString()));
            UserClaims.Add(CreateUserClaim(user, AppClaimTypes.UserId, id.ToString()));

            return(user);
        }
コード例 #21
0
        public OpenIdAuthenticationParameters(IAuthenticationResponse authenticationResponse)
        {
            ExternalIdentifier        = authenticationResponse.ClaimedIdentifier;
            ExternalDisplayIdentifier = authenticationResponse.FriendlyIdentifierForDisplay;

            _claims = new List <UserClaims>();
            var claimsResponseTranslator = new OpenIdClaimsResponseClaimsTranslator();
            var claims1 = claimsResponseTranslator.Translate(authenticationResponse.GetExtension <ClaimsResponse>());

            if (claims1 != null)
            {
                UserClaims.Add(claims1);
            }

            var fetchResponseTranslator = new OpenIdFetchResponseClaimsTranslator();
            var claims2 = fetchResponseTranslator.Translate(authenticationResponse.GetExtension <FetchResponse>());

            if (claims2 != null)
            {
                UserClaims.Add(claims2);
            }
        }
 public CustomProfileIdentityResource()
 {
     UserClaims.Add(ApplicationClaimTypes.PrimaryOrganisationId);
     UserClaims.Add(ApplicationClaimTypes.OrganisationFunction);
 }
コード例 #23
0
 public void AddClaim(IdentityUserClaim <Guid> item)
 {
     item.UserId = Id;
     UserClaims.Add(item);
 }
コード例 #24
0
        //Adding seed data when the application starts
        public void SeedAdminData()
        {
            var adminEmail    = "[email protected]";
            var adminPassword = "******";
            var adminUserId   = string.Empty;

            if (Users.Any(u => u.Email.Equals(adminEmail)))
            {
                adminUserId = (Users.SingleOrDefault(u => u.Email.Equals(adminEmail))).Id;
            }
            else
            {
                var user = new VODUser
                {
                    Email              = adminEmail,
                    UserName           = adminEmail,
                    NormalizedEmail    = adminEmail.ToUpper(),
                    NormalizedUserName = adminEmail.ToUpper()
                };

                var passwordHasher = new PasswordHasher <VODUser>();
                user.PasswordHash = passwordHasher.HashPassword(user, adminPassword);

                Users.Add(user);
                SaveChanges();
                adminUserId = (Users.SingleOrDefault(u => u.Email.Equals(adminEmail))).Id;

                var adminRoleName = "Admin";
                var adminRole     = Roles.SingleOrDefault(r => r.Name.ToLower().Equals(adminRoleName.ToLower()));

                if (adminRole == default)
                {
                    Roles.Add(new IdentityRole()
                    {
                        Name           = adminRoleName,
                        NormalizedName = adminRoleName.ToUpper(),
                        Id             = "1"
                    });
                    SaveChanges();
                    adminRole = Roles.SingleOrDefault(r => r.Name.ToLower().Equals(adminRoleName.ToLower()));
                }

                if (!adminUserId.Equals(string.Empty))
                {
                    if (adminRole != default)
                    {
                        var userRoleExists = UserRoles.Any(ur => ur.RoleId.Equals(adminRole.Id) && ur.UserId.Equals(adminUserId));
                        if (!userRoleExists)
                        {
                            UserRoles.Add(new IdentityUserRole <string> {
                                RoleId = adminRole.Id, UserId = adminUserId
                            });
                        }
                    }
                }

                var claimType       = "Admin";
                var userClaimExists = UserClaims.Any(uc => uc.ClaimType.ToLower().Equals(claimType.ToLower()) && uc.UserId.Equals(adminUserId));

                if (!userClaimExists)
                {
                    UserClaims.Add(new IdentityUserClaim <string> {
                        ClaimType = claimType, ClaimValue = "true", UserId = adminUserId
                    });
                }

                claimType       = "VODUser";
                userClaimExists = UserClaims.Any(uc => uc.ClaimType.ToLower().Equals(claimType.ToLower()) && uc.UserId.Equals(adminUserId));

                if (!userClaimExists)
                {
                    UserClaims.Add(new IdentityUserClaim <string> {
                        ClaimType = claimType, ClaimValue = "true", UserId = adminUserId
                    });
                }
            }
            SaveChanges();
        }
コード例 #25
0
ファイル: IdentityResource.cs プロジェクト: shanyipeng/KissU
 public virtual void AddUserClaim([NotNull] string type)
 {
     UserClaims.Add(new IdentityClaim(Id, type));
 }
コード例 #26
0
 public ProfileWithRoleIdentityResource()
 {
     UserClaims.Add(JwtClaimTypes.Role);
 }
コード例 #27
0
        public async Task <IActionResult> OnGet(int?id)
        {
            if (id.HasValue)
            {
                ViewData["Editing"] = true;
                ApiResource         = await _context.ApiResources
                                      .AsNoTracking()
                                      .Include(a => a.Scopes).ThenInclude(s => s.UserClaims)
                                      .Include(a => a.Secrets)
                                      .Include(a => a.UserClaims)
                                      .SingleOrDefaultAsync(r => r.Id == id.Value);

                ViewData["Title"] = "New Api Resource";
            }
            else
            {
                ViewData["Editing"] = false;
                ViewData["Title"]   = "Create Api Resource";
            }

            var userClaimsOptions            = new List <SelectListItem>();
            var allIdentityResources         = (await _context.IdentityResources.Include(c => c.UserClaims).AsNoTracking().ToListAsync()).Select(i => i.ToModel());
            var allClaimsInIdentityResources = allIdentityResources.SelectMany(c => c.UserClaims).Distinct();
            var allPossibleClaimTypes        = typeof(JwtClaimTypes).GetFields().Select(t => t.GetValue(null).ToString()).ToList();
            var missingClaimTypesOnDatabase  = allPossibleClaimTypes.Except(allClaimsInIdentityResources).OrderBy(v => v).ToList();
            var claimTypesByIdentityResource = allIdentityResources
                                               .OrderBy(r => r.Name)
                                               .ToDictionary(r => r.Name, r => r.UserClaims.OrderBy(c => c).Select(c => c));

            foreach (var claimType in missingClaimTypesOnDatabase)
            {
                var item = new SelectListItem(claimType, claimType, false, false);
                userClaimsOptions.Add(item);
            }

            foreach (var g in claimTypesByIdentityResource)
            {
                var group = new SelectListGroup
                {
                    Name = g.Key
                };
                foreach (var claim in g.Value)
                {
                    var item = new SelectListItem(claim, claim, false, false)
                    {
                        Group = group
                    };
                    userClaimsOptions.Add(item);
                }
            }

            ViewData["UserClaimsOptions"] = userClaimsOptions;

            if (ApiResource.UserClaims != null && ApiResource.UserClaims.Any())
            {
                foreach (var userClaim in ApiResource.UserClaims.Select(c => c.Type))
                {
                    UserClaims.Add(userClaim);
                }
            }

            if (ApiResource.Scopes != null && ApiResource.Scopes.Any())
            {
                foreach (var scope in ApiResource.Scopes)
                {
                    if (scope.UserClaims != null && scope.UserClaims.Any())
                    {
                        ScopeUserClaims.Add(scope.Id.ToString(), scope.UserClaims.Select(c => c.Type).ToList());
                    }
                    else
                    {
                        ScopeUserClaims.Add(scope.Id.ToString(), new List <string>());
                    }
                }
            }

            return(Page());
        }
コード例 #28
0
 public virtual void AddUserClaim([NotNull] string type)
 {
     UserClaims.Add(new ApiScopeClaim(Id, type));
 }
コード例 #29
0
 public virtual void AddUserClaim([NotNull] string type)
 {
     UserClaims.Add(new ApiResourceClaimDto(Id, type));
 }
コード例 #30
0
 public FoodTrackerProfile()
 {
     UserClaims.Add(JwtClaimTypes.Role);
 }