wi3land / ionic-appauth

Intergration for OpenId/AppAuth-JS into Ionic V3/4/5
MIT License
95 stars 74 forks source link

Vu3 + Keycloak #367

Open Excel1 opened 2 months ago

Excel1 commented 2 months ago

I want to connect my Vue3 App with Keycloak by using this Plugin.

My AuthService

import { AuthService, IAuthConfig } from 'ionic-appauth';

let  authService: AuthService;
export const authConfig: IAuthConfig = {
  client_id: 'treasurer',
  server_host: 'http://192.168.188.20:8080/auth/realms/master',
  redirect_url: 'http://192.168.188.20:9000',
  end_session_redirect_url: 'http://192.168.188.20:9000',
  scopes: 'openid profile email offline_access',
  pkce: true
};

export default {
  async initAuth() {
    try {
      authService = new AuthService();
      authService.authConfig = authConfig;
      await authService.init();
      return authService;
    } catch (error) {
      console.error('Auth initialization error:', error);
      throw error;
    }
  },
  async login() {
    try {
      await authService.signIn();
    } catch (error) {
      console.error(error);
    }
  },
  async logout() {
    try {
      await authService.signOut();
    } catch (error) {
      console.error(error);
    }
  },
  async getAuthService() {
    if (!authService) {
      authService = await this.initAuth();
    }

    console.log(authService)
    return authService;
  }
};

My login Method.

const login = () => {
  console.log('login')
  AuthenticationService.getAuthService().then((authservice) => {
    authservice.signIn().then((user) => {
      console.log(user)

    });
  })
}

If i click on login my authService got initalised but i dont get redirected or anything else is coming up in the logs. Is my config wrong?