diff --git a/keycloak-js/index.d.ts b/keycloak-js/index.d.ts index 2cd417da6b..540084d6fd 100644 --- a/keycloak-js/index.d.ts +++ b/keycloak-js/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for keycloak-js 2.4 +// Type definitions for keycloak-js 2.5 // Project: https://github.com/keycloak/keycloak // Definitions by: Brett Epps // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped diff --git a/keycloak-js/keycloak-authz.d.ts b/keycloak-js/keycloak-authz.d.ts new file mode 100644 index 0000000000..4db057ad97 --- /dev/null +++ b/keycloak-js/keycloak-authz.d.ts @@ -0,0 +1,39 @@ +import * as Keycloak from 'keycloak-js'; + +export as namespace KeycloakAuthorization; + +export = KeycloakAuthorization; + +/** + * Creates a new Keycloak client instance. + * @param config Path to a JSON config file or a plain config object. + */ +declare function KeycloakAuthorization(keycloak: Keycloak.KeycloakInstance): KeycloakAuthorization.KeycloakAuthorizationInstance; + +declare namespace KeycloakAuthorization { + export interface KeycloakAuthorizationPromise { + then(onGrant: (rpt: string) => void, onDeny: () => void, onError: () => void): void; + } + + export interface KeycloakAuthorizationInstance { + rpt: any; + config: { rpt_endpoint: string }; + + init(): void; + + /** + * This method enables client applications to better integrate with resource servers protected by a Keycloak + * policy enforcer. + * + * In this case, the resource server will respond with a 401 status code and a WWW-Authenticate header holding the + * necessary information to ask a Keycloak server for authorization data using both UMA and Entitlement protocol, + * depending on how the policy enforcer at the resource server was configured. + */ + authorize(wwwAuthenticateHeader: string): KeycloakAuthorizationPromise; + + /** + * Obtains all entitlements from a Keycloak server based on a given resourceServerId. + */ + entitlement(resourceServerId: string, entitlementRequest: {}): KeycloakAuthorizationPromise; + } +} diff --git a/keycloak-js/keycloak-js-tests.ts b/keycloak-js/keycloak-js-tests.ts index f0957d2114..dc97d8da18 100644 --- a/keycloak-js/keycloak-js-tests.ts +++ b/keycloak-js/keycloak-js-tests.ts @@ -11,4 +11,8 @@ import { KeycloakResponseType } from 'keycloak-js'; +import * as KeycloakAuthorization from 'keycloak-js/keycloak-authz'; +import { KeycloakAuthorizationPromise } from 'keycloak-js/keycloak-authz'; + let keycloak = Keycloak(); +let keycloakAuthz = KeycloakAuthorization(keycloak); diff --git a/keycloak-js/tsconfig.json b/keycloak-js/tsconfig.json index 02d8f5053a..7ac994a5dc 100644 --- a/keycloak-js/tsconfig.json +++ b/keycloak-js/tsconfig.json @@ -17,6 +17,7 @@ }, "files": [ "index.d.ts", + "keycloak-authz.d.ts", "keycloak-js-tests.ts" ] -} \ No newline at end of file +}