我试图动态设置令牌到期时间,但它似乎只是默认为20分钟.
这是我的ConfigureAuth:
public void ConfigureAuth(IAppBuilder app)
{
OAuthOptions = new OAuthAuthorizationServerOptions
{
TokenEndpointPath = new PathString("/Token"),
Provider = new ApplicationOAuthProvider(""),
// In production mode set AllowInsecureHttp = false
AllowInsecureHttp = true
};
// Enable the application to use bearer tokens to authenticate users
app.UseOAuthBearerTokens(OAuthOptions);
}
Run Code Online (Sandbox Code Playgroud)
这是我的GrantResourceOwnerCredentials方法:
public override Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
var hasValidLogin = (new login().authenticate(context.UserName, context.Password, "") == "valid");
if (hasValidLogin == false)
{
context.SetError("invalid_grant", "The user name or password is incorrect.");
return …Run Code Online (Sandbox Code Playgroud) 我正在使用Microsoft Web API 2和Protobuf-net来序列化我的数据.一切都运行得很好,除非我想将二进制数据发送到Web API控制器.我最终得到500错误.
这是目前可行还是仅限于序列化?为了验证我的响应是否正确,我使用了ProtobufJS并对其进行了正确解码.为了查明我的问题,我将其排除在外,并在收到后直接发送了我的回复.任何帮助设置将不胜感激.
Web API控制器
public class UserController : ApiController
{
// GET api/<controller>
public User Get()
{
var user = new User{ Id = "ABC1", FirstName = "John", LastName = "Doe" };
return user;
}
// GET api/user/
public void Post(User user)
{
var type = "POST";
}
}
Run Code Online (Sandbox Code Playgroud)
模型
[ProtoContract]
public class User
{
[ProtoMember(1)]
public string Id { get; set; }
[ProtoMember(2)]
public string FirstName { get; set; }
[ProtoMember(3)]
public string LastName { …Run Code Online (Sandbox Code Playgroud)