首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用LinkedIn的Range6社交登录

使用LinkedIn的Range6社交登录
EN

Stack Overflow用户
提问于 2018-11-15 16:02:04
回答 1查看 6.7K关注 0票数 5

在过去的几天里,我一直在尝试在LinkedIn上实现一个用户的登录,但是我发现了一些错误,在谷歌上的搜索结果并不理想。

  1. 当我的登录页面被加载时,LinkedIn的弹出窗口就会自动打开,即使我没有点击LinkedIn登录按钮。
  2. 当我单击该按钮时,将打开LinkedIn的登录弹出。但是,在提供证书之后,我得到了以下错误:

这是我的app.module.ts

代码语言:javascript
复制
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 { }

这是我的部件

代码语言:javascript
复制
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);
    });
  }

}
EN

回答 1

Stack Overflow用户

发布于 2019-05-07 10:53:28

可能你在使用Javascript,如果是的话-

LinkedIn不再支持JavaScript SDK。推荐的方法是使用OAuth 2.0和LinkedIn的API。

我们的JavaScript和移动软件开发工具包(SDK)将停止工作。开发人员需要从他们的应用程序中直接迁移到使用OAuth 2.0。

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

类似问题- Is sign in with LinkedIn API CDN(https://platform.linkedin.com/in.js) broken?

使用LinkedIn登录的另一种方法是LinkedIn Rest和OAuth 2.0

使用LinkedIn 2.0实现OAuth Rest的一些有用的链接-

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53323356

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档