Example #1
0
        public async Task setting_default_scopes_impact_new_users()
        {
            var user    = TestHelper.StObjMap.StObjs.Obtain <UserTable>();
            var p       = TestHelper.StObjMap.StObjs.Obtain <Package>();
            var factory = TestHelper.StObjMap.StObjs.Obtain <IPocoFactory <IUserGitHubInfo> >();

            using (var ctx = new SqlStandardCallContext())
            {
                AuthScopeSet original = await p.ReadDefaultScopeSetAsync(ctx);

                original.Contains("nimp").Should().BeFalse();
                original.Contains("thing").Should().BeFalse();
                original.Contains("other").Should().BeFalse();

                {
                    int id = await user.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString());

                    IUserGitHubInfo userInfo = factory.Create();
                    userInfo.GitHubAccountId = Guid.NewGuid().ToString();
                    await p.UserGitHubTable.CreateOrUpdateGitHubUserAsync(ctx, 1, id, userInfo);

                    var info = await p.UserGitHubTable.FindKnownUserInfoAsync(ctx, userInfo.GitHubAccountId);

                    AuthScopeSet userSet = await p.ReadScopeSetAsync(ctx, info.UserId);

                    userSet.ToString().Should().Be(original.ToString());
                }
                AuthScopeSet replaced = original.Clone();
                replaced.Add(new AuthScopeItem("nimp"));
                replaced.Add(new AuthScopeItem("thing", ScopeWARStatus.Rejected));
                replaced.Add(new AuthScopeItem("other", ScopeWARStatus.Accepted));
                await p.AuthScopeSetTable.SetScopesAsync(ctx, 1, replaced);

                var readback = await p.ReadDefaultScopeSetAsync(ctx);

                readback.ToString().Should().Be(replaced.ToString());
                // Default scopes have non W status!
                // This must not impact new users: their satus must always be be W.
                readback.ToString().Should().Contain("[R]thing")
                .And.Contain("[A]other");

                {
                    int id = await user.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString());

                    IUserGitHubInfo userInfo = p.UserGitHubTable.CreateUserInfo <IUserGitHubInfo>();
                    userInfo.GitHubAccountId = Guid.NewGuid().ToString();
                    await p.UserGitHubTable.CreateOrUpdateGitHubUserAsync(ctx, 1, id, userInfo, UCLMode.CreateOnly | UCLMode.UpdateOnly);

                    userInfo = (IUserGitHubInfo)(await p.UserGitHubTable.FindKnownUserInfoAsync(ctx, userInfo.GitHubAccountId)).Info;
                    AuthScopeSet userSet = await p.ReadScopeSetAsync(ctx, id);

                    userSet.ToString().Should().Contain("[W]thing")
                    .And.Contain("[W]other")
                    .And.Contain("[W]nimp");
                }
                await p.AuthScopeSetTable.SetScopesAsync(ctx, 1, original);
            }
        }
Example #2
0
        /// <summary>
        /// Challenges <see cref="IUserGitHubInfo"/> data to identify a user.
        /// Note that a successful challenge may have side effects such as updating claims, access tokens or other data
        /// related to the user and this provider.
        /// </summary>
        /// <param name="ctx">The call context to use.</param>
        /// <param name="info">The payload to challenge.</param>
        /// <param name="actualLogin">Set it to false to avoid login side-effect (such as updating the LastLoginTime) on success.</param>
        /// <returns>The login result.</returns>
        public LoginResult LoginUser(ISqlCallContext ctx, IUserGitHubInfo info, bool actualLogin = true)
        {
            var mode = actualLogin
                        ? UCLMode.UpdateOnly | UCLMode.WithActualLogin
                        : UCLMode.UpdateOnly | UCLMode.WithCheckLogin;
            var r = UserGitHubUCL(ctx, 1, 0, info, mode);

            return(r.LoginResult);
        }
Example #3
0
 protected abstract UCLResult UserGitHubUCL(
     ISqlCallContext ctx,
     int actorId,
     int userId,
     [ParameterSource] IUserGitHubInfo info,
     UCLMode mode);
Example #4
0
 /// <summary>
 /// Creates or updates a user entry for this provider.
 /// This is the "binding account" feature since it binds an external identity to
 /// an already existing user that may already be registered into other authencation providers.
 /// </summary>
 /// <param name="ctx">The call context to use.</param>
 /// <param name="actorId">The acting actor identifier.</param>
 /// <param name="userId">The user identifier that must be registered.</param>
 /// <param name="info">Provider specific data: the <see cref="IUserGitHubInfo"/> poco.</param>
 /// <param name="mode">Optionnaly configures Create, Update only or WithLogin behavior.</param>
 /// <returns>The result.</returns>
 public UCLResult CreateOrUpdateGitHubUser(ISqlCallContext ctx, int actorId, int userId, IUserGitHubInfo info, UCLMode mode = UCLMode.CreateOrUpdate)
 {
     return(UserGitHubUCL(ctx, actorId, userId, info, mode));
 }