public void Authorize() { Authorization authorization = controller.Create(model); Assert.True(authorizationRepository.Exists(authorization)); Assert.AreEqual(client, authorization.Client); Assert.AreEqual(connection, authorization.Connection); Assert.NotNull(authorization.AccessToken); ValidateAccessToken(authorization); }
public IActionResult Login([FromBody] Login user) { if (user == null) { return(BadRequest("Invalid client request")); } var getUser = _jWTDbDBContext.Users.Where(r => r.Username == user.Username && r.Password == user.Password); if (getUser.Count() == 0) { return(Unauthorized()); } var dbUser = getUser.FirstOrDefault(); MongoData.Models.DTO.AuthorizationDTO authorization = new MongoData.Models.DTO.AuthorizationDTO { Id_user = dbUser.Id_user, Username = dbUser.Username, Role = dbUser.Role, GUID = dbUser.GUID, Id_state = dbUser.Id_state }; string mongoAuthorizationDocumentId = _authorizationController.Create(authorization); var tokenString = Controllers.Classes.JWT.GetToken(dbUser.Id_user.ToString(), dbUser.Username, dbUser.GUID, mongoAuthorizationDocumentId); return(Ok(new { Token = tokenString })); }
private Authorization CreateAuthorization() { Account account = accountRepository.Save(new Account { Name = "name", Surname = "surname", Username = "******", Email = "*****@*****.**" }); Connection connection = connectionRepository.Save(new Connection { Account = account }); AuthorizeModel model = new AuthorizeModel { ClientId = client.Id, ConnectionId = connection.Id, SecretCode = client.SecretCode }; Authorization authorization = controller.Create(model); return(authorization); }