Was ist die Standard-OAuth-AccessTokenFormat Umsetzung in OWIN für IIS-host?

Web-API-2-OWIN Bearer-token-Authentifizierung - AccessTokenFormat null?

Den default-Token-endpoints funktioniert einwandfrei und ich konnte token von dort
aber ich muss an die AccessTokenFormat.Schützen-Methode auf ein ticket zu generieren accessToken für externalLogin.

Grundsätzlich meine Implementierung ist so ziemlich das gleiche wie dieses, und ich hatte das gleiche problem der AccessTokenFormat null ist.
Aus der Dokumentation es sagt:

Format die Daten zum Schutz der Informationen in der access-token. Wenn Sie nicht von der Anwendung Standard-Daten-Schutz-provider richtet auf dem host-server. Die SystemWeb-host auf dem IIS verwenden ASP.NET Maschine, Schlüssel, data protection, und HttpListener und anderen selbst gehosteten Server verwenden Sie DPAPI, data protection. Wenn eine andere access-token-Anbieter oder format zugeordnet ist, einen kompatiblen Instanz zugewiesen werden muss, die OAuthBearerAuthenticationOptions.AccessTokenProvider oder OAuthBearerAuthenticationOptions.AccessTokenFormat Eigenschaft der Ressource server.

Sieht es für mich aus, dass, wenn die AccessTokenFormat nicht zugewiesen ist, wird der host eine grundlegende Implementierung für Sie. Aber ich sehe es nicht funktioniert hier.
Gibt es eine Möglichkeit, die ich finden konnte die default-Implementierung der ISecureDataFormatAccessTokenFormat und weisen Sie der Variablen manuell?

Oder hat jemand andere Ideen, wie man dies löst?

UPDATE:
Ich bekomme den source code für das katana und finden Sie die OAuthAuthorizationServerMiddleware Klasse, aus dem source-code, den ich sehen konnte, Sie den folgenden code:

if (Options.AccessTokenFormat == null)
        {
            IDataProtector dataProtecter = app.CreateDataProtector(
                typeof(OAuthAuthorizationServerMiddleware).Namespace,
                "Access_Token", "v1");
            Options.AccessTokenFormat = new TicketDataFormat(dataProtecter);
        }

In meinem Systemstart.Auth, hier ist mein code:

     static Startup()
    {
        PublicClientId = "self";

        UserManagerFactory = () => new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));

        OAuthOptions = new OAuthAuthorizationServerOptions()
        {
            TokenEndpointPath = new PathString("/Token"),
            AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"),
            Provider = new ApplicationOAuthProvider(PublicClientId, UserManagerFactory),
            AccessTokenExpireTimeSpan = TimeSpan.FromDays(14),
            AllowInsecureHttp = true
        };

        OAuthBearerOptions = new OAuthBearerAuthenticationOptions();
        OAuthBearerOptions.AccessTokenFormat = OAuthOptions.AccessTokenFormat;
        OAuthBearerOptions.AccessTokenProvider = OAuthOptions.AccessTokenProvider;
        OAuthBearerOptions.AuthenticationMode = OAuthOptions.AuthenticationMode;
        OAuthBearerOptions.AuthenticationType = OAuthOptions.AuthenticationType;
        OAuthBearerOptions.Description = OAuthOptions.Description;

        OAuthBearerOptions.Provider = new CustomBearerAuthenticationProvider();
        OAuthBearerOptions.SystemClock = OAuthOptions.SystemClock;
    }

    public void ConfigureAuth(IAppBuilder app)
    {
        //Configure the db context and user manager to use a single instance per request
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);


        app.UseOAuthAuthorizationServer(OAuthOptions);

        //Enable the application to use bearer tokens to authenticate users
        app.UseOAuthBearerTokens(OAuthOptions);
        //Enable the application to use a cookie to store information for the signed in user
        //and to use a cookie to temporarily store information about a user logging in with a third party login provider
        //Configure the sign in cookie
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });
        //Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

}

Ich habe auch das folgende in der WebApiConfig

//Web API configuration and services
        //Configure Web API to use only bearer token authentication.
        config.SuppressDefaultHostAuthentication();
        config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

Ich bin mir nicht sicher, warum
app.UseOAuthAuthorizationServer(OAuthOptions); Einstellung nicht accessTokenFormat

InformationsquelleAutor Wei | 2014-05-14

Schreibe einen Kommentar