0
I have a question about the token bearer. I have two scenarios in my application. 1º is an admin panel that works with ASP.NET MVC and Angularjs and the 2nd is the WEB Api that exchanges requests with a WPF application. My question is about the token, if it is indifferent I use it for an ASP.NET MVC controller and a web api controller.
public class AuthorizationServerProvider : OAuthAuthorizationServerProvider
{
public override async Task ValidateClientAuthentication(OAuthValidateClientAuthenticationContext context)
{
context.Validated();
}
public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
try
{
DbEngine db = new DbEngine();
var user = db.AutenticacaoAPI(context.UserName, context.Password);
var identity = new ClaimsIdentity(context.Options.AuthenticationType);
if (user.Status)
{
identity.AddClaim(new Claim(ClaimTypes.Name, user.Value.ST_NOME));
identity.AddClaim(new Claim(ClaimTypes.Email, user.Value.ST_LOGIN));
}
context.Validated(identity);
}
catch
{
context.SetError("Usuário e senha inválidos", "Error");
}
}
}
and the Controller code to request user information only to test the service
[Authorize]
[HttpGet]
public JsonResult UserInfo(string login)
{
using (DbEngine db = new DbEngine())
{
try
{
return new JsonResult
{
Data = db.GetUser(login),
JsonRequestBehavior = JsonRequestBehavior.AllowGet
};
}
catch (Exception ex)
{
return ex.ReturnException(HttpStatusCode.InternalServerError);
}
}
}
Here is the return of the token
And here the call that returns this error even with the token in the header
I appreciate the help.
Thanks, I’ll try to deactivate to see if it works. I appreciate your help
– Angélica Flausino
I deactivated Lazy Load but continued the same problem, so I did some more research and found the solution at this link: http://stackoverflow.com/questions/5588143/ef-4-code-first-json-circular-reference-serialization-error so I just entered
db.Configuration.ProxyCreationEnabled = false;
and I got to do the get. I’ll mark it as the right answer because you gave me the right direction to solve my problem, I appreciate your help.– Angélica Flausino