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登录功能。

相关内容

热门资讯

分享开挂内幕"决战卡... 分享开挂内幕"决战卡五星辅助器下载"开挂(工具)辅助工具有挂功能-科技教程《详细加薇13670430...
透视辅助"福建兄弟1... 透视辅助"福建兄弟13水破解版"开挂(脚本)辅助脚本有挂助手-攻略教程 【无需打开直接搜索加薇136...
玩家必看攻略"四川游... 玩家必看攻略"四川游戏家园辅助软件下载"开挂(下载)辅助下载有挂秘籍-必备教程四川游戏家园辅助软件下...
透视挂"微信三哥玩辅... 透视挂"微信三哥玩辅助器"开挂(下载)辅助下载真实有挂-力荐教程;无需打开直接搜索加(薇:13670...
实测教程"微信小程序... 较多好评“微乐万能挂官网”开挂(透视)辅助教程 了解更多开挂安装加(136704302)微信号是一款...
一分钟了解"逍遥湖北... 一分钟了解"逍遥湖北微信辅助"开挂(软件)辅助软件新版有挂-教你攻略 【无需打开直接搜索加薇1367...
每日必看"微信小程序... 每日必看"微信小程序辅助器免费版"开挂(工具)辅助工具有挂方式-德州教程您好:微信小程序辅助器免费版...
透视安装"微信老友广... 您好:微信老友广东辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的...
大家学习交流"心悦填... 大家学习交流"心悦填大坑万能辅助器"开挂(下载)辅助下载有挂辅助-微扑克教程;打开点击测试直接进入微...
重大通报"新道游拼十... 新道游拼十辅助器是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加我微...