Angular 6 social login with LinkedIn

Viewed 6623

For the last few days, I've been trying to implement the logging in of a user on LinkedIn, but I'm getting errors and a search on Google was not fruitful.

  1. When ever my login page is getting loaded, the popup for LinkedIn is automatically getting opened even though I am not clicking on the LinkedIn login button.

  2. When I am clicking on the button, the login popup for LinkedIn opens. But, after providing the credential, I am getting these errors :

    Unhandled promise rejection TypeError: "i.getCredentials is not a function"

This is my app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { HttpClientModule } from '@angular/common/http';
import { ReactiveFormsModule, FormsModule} from '@angular/forms';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { MaincomponentComponent } from './maincomponent/maincomponent.component';
import { HomeComponentComponent } from './maincomponent/home-component/home-component.component';
import { SignupComponentComponent } from './maincomponent/signup-component/signup-component.component';
import { EqualValidatorDirective } from './directives/equal-validator.directive';
import { UniqueEmailValidatorDirective } from './directives/unique-email-validator.directive';
import { UniqueUsernameValidatorDirective } from './directives/unique-username-validator.directive';
import { UniquePhoneNumberValidatorDirective } from './directives/unique-phone-number-validator.directive';
import { DatePipe } from '@angular/common';
import { TokenValidationComponentComponent } from './maincomponent/token-validation-component/token-validation-component.component';
import { LoginComponentComponent } from './maincomponent/login-component/login-component.component';
import { SocialLoginModule, AuthServiceConfig } from 'angularx-social-login';
import { LinkedInLoginProvider} from 'angularx-social-login';

const config = new AuthServiceConfig([
  {
    id: LinkedInLoginProvider.PROVIDER_ID,
    provider: new LinkedInLoginProvider('81fbs3fvxxwl73')
  }
]);

export function provideConfig() {
  return config;
}

@NgModule({
  declarations: [
    AppComponent,
    MaincomponentComponent,
    HomeComponentComponent,
    SignupComponentComponent,
    EqualValidatorDirective,
    UniqueEmailValidatorDirective,
    UniqueUsernameValidatorDirective,
    UniquePhoneNumberValidatorDirective,
    TokenValidationComponentComponent,
    LoginComponentComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    ReactiveFormsModule,
    SocialLoginModule
  ],
  providers: [DatePipe,
    {
      provide: AuthServiceConfig,
      useFactory: provideConfig
    }
],
  bootstrap: [AppComponent]
})
export class AppModule { }

And here is my component

import { Component, OnInit } from '@angular/core';
import { Router, ActivatedRoute } from '@angular/router';
import { AuthService } from 'angularx-social-login';
import { LinkedInLoginProvider } from 'angularx-social-login';
import { UserApiService } from '../../services/user-api.service';
import { Login } from '../../models/Login.model';
import { NgForm } from '@angular/forms';
import { SocialUser } from 'angularx-social-login';
import swal from 'sweetalert2';
@Component({
  selector: 'app-login-component',
  templateUrl: './login-component.component.html',
  styleUrls: ['./login-component.component.scss']
})
export class LoginComponentComponent implements OnInit {
  login: Login;
  userRoles: any;
  return_url: any;
  role_id: any = '5b119f9f80c2292148006613';
  user: SocialUser;
  activeRec = {
    'background-color': '#fdb614',
    'color': '#fff'
  };
  activeJobSeeker = {
    'background-color': 'white',
    'color': '#fff'
  };

  constructor(private userApi: UserApiService, private router: Router, private route: ActivatedRoute, private authService: AuthService) { }

  ngOnInit() {
    this.userApi.getUserRoles().subscribe((data: any) => {
      this.userRoles = data.data.roles;
    });
    this.resetForm();
  }
  resetForm(form ?: NgForm) {
    if (form != null) {
        form.reset();
    }
    this.login = {
        username: '',
        password: ''
    };
  }
  changeRole(role_id_param, role) {
    this.role_id = role_id_param;
    if (role === 0) {
      this.activeRec = {
        'background-color': '#fdb614',
        'color': '#fff'
      };
      this.activeJobSeeker = {
        'background-color': 'white',
        'color': '#fff'
      };
    } else {
      this.activeJobSeeker = {
        'background-color': '#fdb614',
        'color': '#fff'
      };
      this.activeRec = {
        'background-color': 'white',
        'color': '#fff'
      };
    }
  }

  OnSubmit(form: NgForm): void {
    this.userApi.userAuthentication(form.value.username, form.value.password).subscribe((data: any) => {
      if (data.status === true) {
          localStorage.setItem('userToken', data.data.token);
          this.return_url = this.route.snapshot.queryParams['returnUrl'] ;
          if (typeof this.return_url === 'undefined') {
            swal({
              type: 'success',
              title: 'Yeah',
              text: 'Welcome to UberManPower',
              showConfirmButton: false,
              timer: 1500
            });
            this.router.navigate(['']);
          } else {
      console.log('TEST');
          }
      } else {
          swal({
              type: 'error',
              title: 'Oops...',
              text: data.message
          });
      }
  });
  }

  signInWithLinkedIn(): void {
    this.authService.signIn(LinkedInLoginProvider.PROVIDER_ID).then((user) => {
      this.user = user;
      console.log(this.user);
    });
  }

}
1 Answers

Probably you are using the Javascript SDK and If yes then-

LinkedIn no longer supports the JavaScript SDK. The recommended approach is to use OAuth 2.0 and LinkedIn's API.

Our JavaScript and Mobile Software Development Kits (SDKs) will stop working. Developers will need to migrate to using OAuth 2.0 directly from their apps.

https://engineering.linkedin.com/blog/2018/12/developer-program-updates

Similar question- Is sign in with LinkedIn API CDN(https://platform.linkedin.com/in.js) broken?


Another way for the login with LinkedIn is LinkedIn Rest API with OAuth 2.0

Some useful links for implementation of LinkedIn Rest API with OAuth 2.0 -

Related