Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keycloak angular 2

I'm trying out keycloak with angular 2. I'm making a service where I do as they do in their doc. However it always returns not authenticated even though I'm connected when I connect to my account keycloak url (auth/realms/wb/account).

declare var Keycloak: any;

@Injectable()
export class UserMockService {

    constructor() {
        let keycloak: any = new Keycloak('assets/keycloak.json');

         keycloak.init().success(function(authenticated) {
            alert(authenticated ? 'authenticated' : 'not authenticated');
        }).error(function() {
            alert('failed to initialize');
        });
     }
}

Yes it does find the json.

{
  "realm": "wb",
  "auth-server-url": "http://192.168.99.100/auth",
  "ssl-required": "external",
  "resource": "wb",
  "public-client": true
}

Oh yeah and before I forget: what the heck is the URL to redirect user to connect to my app ? Seems like it should be something easy to find but their doc is so scattered.. To connect at the moment I use /auth/realms/wb/account but that's the url to connect to the account settings..

So the flow is like this :

  • user goes to http://192.168.99.100
  • user clicks login buttons
  • user is redirected to the login URL, at the moment I use http://192.168.99.100/auth/realms/wb/account.
  • user comes back on the app and the angular service tells me if the user is logged in.
like image 807
Ced Avatar asked Jan 05 '23 02:01

Ced


1 Answers

I can recommend having a look into the official Angular 2 client app example on the Keycloak GitHub.

A month ago, I successfully created a Keycloak secured Angular 2 app using the snippets out of this example.

like image 170
Yuri Avatar answered Jan 13 '23 20:01

Yuri