Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After login success parsedToken, isAuthenticated and profile is null or false (v 0.9) #18

Open
pako-g opened this issue Aug 25, 2017 · 8 comments

Comments

@pako-g
Copy link

pako-g commented Aug 25, 2017

After login the following variables are false or null

parsenToken
isAuthenticated
profile

this is the HomeComponent

export class HomeComponent implements OnInit {

  private parsedToken: any;
  private isAuthenticated: boolean;

  products: string[] = [];
  private profile: any;
  constructor(private keycloak: Keycloak,
              private keycloakAuthz: KeycloakAuthorization,
              private http: Http) {


    Keycloak.authenticatedObs.subscribe(auth => {
      this.isAuthenticated = auth;
      this.parsedToken = keycloak.tokenParsed;
      /*console.info('APP: authentication status changed...');*/
    });
  }

  ngOnInit() {
   /* console.info('APP : initializing home component...');*/

    this.keycloakAuthz.init();

    // comment or change regarding your app-name
    this.keycloak.config = 'keycloak.json';

    this.keycloak.init({
      checkLoginIframe: false
    });
  }


  login() {
    this.keycloak.login({});
  }

  logout() {
    this.keycloak.logout({});
  }

  loadProfile() {
    this.keycloak.loadUserProfile().subscribe(profile => {
      this.profile = profile;
    });
  }
}

I have change the Keycloak.tokenParsed with keycloak.tokenParsed

after login success
schermata del 2017-08-25 19-45-11

@ebondu
Copy link
Owner

ebondu commented Aug 28, 2017

I have change the Keycloak.tokenParsed with keycloak.tokenParsed

You are right I didn't update the example/doc yet for changes since 0.9.0.

The authenticatedObs may return false during init phases, you may have to filter the returned values to ensure auth sucess and to get the token :

Keycloak.authenticatedObs.subscribe(authenticated => {
      if (authenticated) {
        this.identity = keycloak.tokenParsed;
      }
});

@pako-g
Copy link
Author

pako-g commented Aug 28, 2017

I tried with

Keycloak.authenticatedObs.subscribe(authenticated => {
      if (authenticated) {
        this.isAuthenticated = authenticated;
        this.parsedToken = keycloak.tokenParsed;
      }
    });

inside the constructor but not work

@pako-g
Copy link
Author

pako-g commented Aug 28, 2017

I can not get the token, login works but I can not load user data, token, and more
authenticated is always false
I also updated to version 0.9.1

@sunmeplz
Copy link

@ebondu Hi! do you plan to publish sources of 0.9.x version?
Thanks

@ebondu
Copy link
Owner

ebondu commented Aug 29, 2017

Hi,
Of course, I will try to push it today.

@ebondu
Copy link
Owner

ebondu commented Aug 29, 2017

I pushed last changes to the ng4 branch

@AlanCrevon
Copy link

Hi @ebondu.

As the documnetation doesn't match the npm version, i can't find a way to make your wrapper work with 0.9.1, even though i can see this is supposed to do exactly what i need the way i want it.

Could you please update your documentation ?

Thanks.
Alan

@ebondu
Copy link
Owner

ebondu commented Sep 18, 2017

Hi @AlanCrevon,
I updated the documentation on the ng4 branch, and I will try to provide an example before the end of the week. Main changes are related to AoT compilation: some static methods of the Keycloak class are now public. That means you need to inject the keycloak and call methods on the injected object instead of calling the method statically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants