angular oauth 2 oidc doesn't work with github idp

24 Views Asked by At

i am trying to test using the angualr outh 2 oidc plugin to integrate github authentication into a project.

I have configured the settings and applied all the necessary functions but when I press the login button nothing happens... it just prints me the console log inside the login() function. How is it possible that nothing happens and I have no errors in the console?

In the github profile I created a new oauth2 application and once I got the client id I inserted it in the angular application the code is below:

auth.service.ts

import { Injectable } from '@angular/core';
import { OAuthService, OAuthEvent } from 'angular-oauth2-oidc';

@Injectable({
  providedIn: 'root'
})
export class AuthService {
  constructor(private oauthService: OAuthService) {
    this.configure();
  }

  configure() {
    this.oauthService.configure({
     clientId: 'MYCLIENTID',
     redirectUri: window.location.origin,
     responseType: 'code',
     scope: 'openid profile email'
    });
  }

  login() {  
    this.oauthService.initImplicitFlow();
    console.log('prova')
  }

  logout() {
    this.oauthService.logOut();
  }

  get token(){
    let claims:any = this.oauthService.getIdentityClaims();
    return claims ? claims : null;
  }
}

app.component.ts

import { Component } from '@angular/core';
import { userInfo } from '../model/userinfo.model';
import { AuthService } from './auth.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
})
export class AppComponent {
  constructor(private authService: AuthService) { 
  }
  login() {
    this.authService.login();
  }
}

app.component.html

import { Component } from '@angular/core';
import { AuthService } from './auth.service';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrl: './app.component.scss',
})
export class AppComponent {
  constructor(private authService: AuthService) {

  }
  login() {
    this.authService.login();
  }
}
0

There are 0 best solutions below