авторизация keycloak с помощью веб-API .net - PullRequest
0 голосов
/ 28 августа 2018

Я пытаюсь авторизовать входящие запросы от углового приложения на стороне сервера веб-API с использованием аутентификации keycloak. После того, как я следовал этому руководству, я успешно получаю токен на предъявителя со всем, включая роли (проверено после расшифровки с помощью токена jwt.io), однако атрибут Authorize (в приложении .net) не является за работой; Роли не проверяются для авторизации пользователя или приложение не может создать ссылку с соответствующим атрибутом. Чего мне не хватает?

это мой код в startup.cs

// Name of the persistent authentication middleware for lookup
const string persistentAuthType = "KeycloakOwinAuthenticationSample_cookie_auth1";

// --- Cookie Authentication Middleware - Persists user sessions between requests
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
    AuthenticationType = persistentAuthType
});
app.SetDefaultSignInAsAuthenticationType(persistentAuthType); // Cookie is primary session store

// --- Keycloak Authentication Middleware - Connects to central Keycloak database
app.UseKeycloakAuthentication(new KeycloakAuthenticationOptions
{

    // App-Specific Settings
    ClientId = "demoapp", // *Required*

    VirtualDirectory = "", // Set this if you use a virtual directory when deploying to IIS

    // Instance-Specific Settings
    Realm = "demo", // Don't change this unless told to do so
    KeycloakUrl = "http://localhost:8080/auth", // Enter your Keycloak URL here

    // Template-Specific Settings
    SignInAsAuthenticationType = persistentAuthType, // Sets the above cookie with the Keycloak data
    AuthenticationType = "KeycloakOwinAuthenticationSample_keycloak_auth1" // Unique identifier for the auth middleware
 , EnableBearerTokenAuth = true 
 });
...