小编use*_*393的帖子

OAuth2 WebApi令牌过期

我试图动态设置令牌到期时间,但它似乎只是默认为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)

asp.net oauth oauth-2.0 asp.net-web-api owin

14
推荐指数
2
解决办法
2万
查看次数

将Protobuf消息发送到Web API失败

我正在使用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)

c# http protocol-buffers protobuf-net asp.net-web-api2

5
推荐指数
0
解决办法
670
查看次数