Beispiel #1
0
        public async Task <IActionResult> AssertionConsumerService()
        {
            // Receive and process the SAML assertion contained in the SAML response.
            // The SAML response is received either as part of IdP-initiated or SP-initiated SSO.
            var ssoResult = await _samlServiceProvider.ReceiveSsoAsync();

            if (string.IsNullOrEmpty(ssoResult.RelayState))
            {
                // This was a test initiated from the manage page
                return(RedirectToAction("Index", "Manage", new { Message = ManageController.ManageMessageId.TestSamlSuccess }));
            }

            // This is a mess, but there's no other way to find the current user because
            // this controller hides the current identity for some reason
            var user = await _userManager.FindByIdAsync(ssoResult.RelayState.Split(',')[0]);

            var universityService = new UniversityService(new SqlUniversityRepository(_dbContext));
            var university        = await universityService.FindByIdAsync(int.Parse(ssoResult.RelayState.Split(',')[1]));

            var authConfigService = new AuthConfigService(new SqlAuthConfigRepository(_dbContext), null);
            var authConfig        = await authConfigService.GetConfigAsync(university);

            await universityService.JoinAsync(user, university, authConfig.OverrideUsernames?ssoResult.UserID : null);

            return(RedirectToAction("Index", "Chat"));
        }
Beispiel #2
0
        public async Task <string> Join([FromBody] NearByResult userChoice)
        {
            var user = await UserService.FindByNameAsync(User.Identity.Name);

            var university = await UniversityService.GetOrCreateAsync(userChoice, await ChannelTemplateService.GetAsync());

            var isAlreadyMember = university.Server.Channels
                                  .Any(ch => ch.Memberships.Any(m => m.User.Equals(user)));

            if (isAlreadyMember)
            {
                return("/Chat");
            }
            if (university.Server.IsAuthEnabled)
            {
                var partner = await AuthConfigService.GetConfigAsync(university);

                return($"/Account/SingleSignOn?partnerName={partner.Name}&relayState={user.Id},{university.Id}");
            }
            await UniversityService.JoinAsync(user, university);

            return("/Chat");
        }