Ablaufdatum des OAuth2-WebApi-Tokens

Ich versuche, eine Token-Ablaufzeit dynamisch festzulegen, aber es scheint, dass die Standardeinstellung weiterhin 20 Minuten beträgt.

Hier ist meine 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);

}

Hier ist meine GrantResourceOwnerCredentials-Methode:

    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 Task.FromResult<object>(null);
        }

        var oAuthIdentity = CreateIdentity(context);
        var oAuthProperties = CreateProperties(context);

        AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, oAuthProperties);

        context.Validated(ticket);
        return Task.FromResult<object>(null);
    }

Und hier ist meine SetProperties-Methode, mit der ich den Ablauf festlegen kann:

    public static AuthenticationProperties CreateProperties(OAuthGrantResourceOwnerCredentialsContext context)
    {

        IDictionary<string, string> data = new Dictionary<string, string>
        {
            { "client_id", context.ClientId }
        };

        var response = new AuthenticationProperties(data);
        response.ExpiresUtc = DateTime.Now.AddMonths(1);

        return response;
    }

Auch danach kehrt das Token zurück:

{
  "access_token": ".....",
  "token_type": "bearer",
  "expires_in": 1199,
  "client_id": ".....",
  ".expires": "Fri, 13 Nov 2015 20:24:06 GMT",
  ".issued": "Fri, 13 Nov 2015 20:04:06 GMT"
}

Haben Sie eine Idee, warum ich den Ablauf nicht dort festlegen kann, wo ich mich gerade befinde? Dieser Server wird eine Vielzahl von verschiedenen Clients mit unterschiedlichen angegebenen Ablaufzeiten verwenden, daher habe ich angenommen, dass dies der richtige Ort ist, um dies zu tun. Gibt es irgendwo anders, wo ich das machen sollte? Vielen Dank

Antworten auf die Frage(8)

Ihre Antwort auf die Frage