public HttpResponseMessage Autentica(string cpf, int codModulo) { var res = new AutenticacaoBL().VerificarPermissao(cpf, codModulo); if (res.Sucesso) { return(Request.CreateResponse(HttpStatusCode.OK, res)); } else { return(Request.CreateResponse(HttpStatusCode.Forbidden, res)); } }
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { AutenticacaoBL Dal = new AutenticacaoBL(); try { var allowedOrigin = context.OwinContext.Get <string>("clientAllowedOrigin"); if (allowedOrigin == null) { allowedOrigin = "*"; } context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin }); //recupera usuario da base de dados Usuario user = await Dal.EfetuarLogin(context.UserName, context.Password); if (user.StatusProcessamento > 0) { context.SetError("invalid_grant", user.MensagemProcessamento); return; } var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); identity.AddClaim(new Claim(ClaimTypes.Role, "user")); identity.AddClaim(new Claim("sub", context.UserName)); #region mapeamento de atributos do usuario logado var props = new AuthenticationProperties(new Dictionary <string, string> { { "userName", context.UserName }, { "nomeUsuario", user.UsuarioNome }, { "perfilUsuario", user.UsuarioPerfil.UsuPerfilNome }, { "usuarioId", user.UsuarioId.ToString() }, { "loginUsuario", user.UsuarioLogin }, { "clienteId", user.Cliente.ClienteId.ToString() } }); #endregion //var session = HttpContext.Current.Session; //session.Add("AuthenticationProperties", props.Dictionary); var ticket = new AuthenticationTicket(identity, props); context.Validated(ticket); } catch (Exception e) { context.SetError("invalid_grant", e.Message); } }
public RefreshTokensController() { _auth = new AutenticacaoBL(); }