AngularSpringBoot应用中的GitHubSSO登录功能无法使用。
创始人
2024-10-29 16:01:16
0
  1. 首先确认是否已经正确配置了GitHub SSO,可以使用其他应用测试是否能正常使用。

  2. 确认Angular和Spring Boot的版本兼容性。

  3. 在Angular应用中,使用ng2-cordova-oauth插件进行GitHub授权登录。例如:

import { CordovaOauth } from 'ng2-cordova-oauth/oauth';
import { Component } from '@angular/core';
 
@Component({
  selector: 'app-root',
  template: ''
})
export class AppComponent {
 
  private cordovaOauth: CordovaOauth = new CordovaOauth();
 
  githubLogin() {
    this.cordovaOauth.login('github').then(success => {
      console.log('GitHub login success!');
      console.log(success);
    }, error => {
      console.log('GitHub login error');
      console.log(error);
    });
  }
}
  1. 在Spring Boot应用中,配置github-oauth2-client并使用@EnableOAuth2Sso注解实现单点登录。例如:
@Configuration
@EnableOAuth2Sso
public class OAuthConfig extends WebSecurityConfigurerAdapter {
 
  @Override
  public void configure(HttpSecurity http) throws Exception {
    http.authorizeRequests()
      .antMatchers("/error**")
      .permitAll()
      .anyRequest()
      .authenticated();
  }
 
  @Bean
  public ClientRegistrationRepository clientRegistrationRepository() {
    return new InMemoryClientRegistrationRepository(githubClientRegistration());
  }
 
  private ClientRegistration githubClientRegistration() {
    return ClientRegistration.withRegistrationId("github")
      .clientId("github-client-id")
      .clientSecret("github-client-secret")
      .authorizationUri("https://github.com/login/oauth/authorize")
      .tokenUri("https://github.com/login/oauth/access_token")
      .userInfoUri("https://api.github.com/user")
      .userNameAttributeName("id")
      .clientName("GitHub")
      .build();
  }
}
  1. 在两个应用中分别测试GitHub SSO登录功能。

相关内容

热门资讯

相较于以往!hhpoker德州... 相较于以往!hhpoker德州有挂吗,hhpoker是内部控制吗,教程书教程(有挂细节)-哔哩哔哩1...
为切实保障!wepoker黑侠... 为切实保障!wepoker黑侠辅助器正版下载(透视)果然真的有挂(有挂规律开挂辅助平台)-哔哩哔哩1...
做出回应!wepoker游戏安... 做出回应!wepoker游戏安装教程,wejoker辅助器要钱玩吗,举措教程(有挂教程)-哔哩哔哩1...
反观!hhpoker开挂教程(... 反观!hhpoker开挂教程(透视)其实确实有挂(有挂教程开挂辅助插件)-哔哩哔哩hhpoker开挂...
日前!we poker游戏下,... 日前!we poker游戏下,pokemmo修改器手机版,窍门教程(有挂教学)-哔哩哔哩1、玩家可以...
此事迅速冲上热搜!wpk辅助(... 此事迅速冲上热搜!wpk辅助(透视)原来确实有挂(有挂细节开挂辅助平台)-哔哩哔哩1、进入到wpk辅...
刚刚!德州透视hhpoker,... 刚刚!德州透视hhpoker,wepoker辅助器官方,指引教程(有挂规律)-哔哩哔哩一、wepok...
近年来!pokerworld软... 近年来!pokerworld软件(透视)一贯真的有挂(有挂教程开挂辅助下载)-哔哩哔哩1、超多福利:...
这一问题亟待解决!hhpoke... 这一问题亟待解决!hhpoker透视工具,约局吧德州真的存在透视吗,方式教程(有挂辅助)-哔哩哔哩;...
事发当天!佛手在线大菠萝智能辅... 事发当天!佛手在线大菠萝智能辅助器(透视)果然是有挂(存在有挂开挂辅助软件)-哔哩哔哩1、佛手在线大...