public async Task <IHttpActionResult> SignInLinkedin(SignInLinkedinModel model)
        {
            this.CheckModelStateIsValid();

            string token;
            var    userSession = this.GetCurrentUserSession();

            if (userSession == null)
            {
                var externalUserDetails = await LinkedinUserDetailsProvider.GetUserDetails(model, Request.GetOwinContext().Request.CallCancelled);

                userSession = _userSessionBusinessLogic.CreateSessionForExternalUser(externalUserDetails);

                token = JwtHelper.Create(userSession);
            }
            else
            {
                Log.InfoFormat("User '{0}' is already signed-in. Reusing existing session.", userSession.UserId);

                // return the bearer token received
                token = Request.Headers.Authorization.Parameter;
            }

            var result = new SignInResultModel
            {
                Token = token
            };

            return(Ok(result));
        }
        public async Task <ActionResult> PostToken(SSOTokenDTO tokendata)
        {
            Console.WriteLine(tokendata);
            try
            {
                UserDTO user = await SSOHelper.GetSSOData(tokendata);

                User databaseUserReturn = await _context.Users.FindAsync(user.Username.ToLower());

                if (databaseUserReturn == null)
                {
                    _context.Users.Add(await UserFactory.Create(user.Username, user.Mail, user.Gn, user.Sn));
                    await _context.SaveChangesAsync();

                    user.AccountType = nameof(Models.User.UserType.User);
                }
                else
                {
                    if (databaseUserReturn.Mail == null)
                    {
                        databaseUserReturn.Mail = user.Mail;
                    }
                    if (databaseUserReturn.GeneralName == null)
                    {
                        databaseUserReturn.GeneralName = user.Gn;
                    }
                    if (databaseUserReturn.Surname == null)
                    {
                        databaseUserReturn.Surname = user.Sn;
                    }
                    _context.Users.Update(databaseUserReturn);
                    await _context.SaveChangesAsync();

                    user.AccountType = databaseUserReturn.AccountType.ToString();
                }

                var response = new { jwt = JwtHelper.Create(user, _configuration.GetValue <String>("APIHostName")) };
                return(Ok(response));
            }
            catch (ArgumentException)
            {
                return(Unauthorized("Authentication Failed"));
            }
        }