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

相关内容

热门资讯

详情透视!德州局透视脚本下载安... 详情透视!德州局透视脚本下载安装最新版本!真是有辅助技巧(有挂辅助)-哔哩哔哩1、让任何用户在无需德...
曝光透视!佛手在线是不是有挂!... 曝光透视!佛手在线是不是有挂!一贯真的是有辅助攻略(确实有挂)-哔哩哔哩暗藏猫腻,小编详细说明佛手在...
必备透视!poker worl... 必备透视!poker world辅助器!真是一直总是有辅助插件(讲解有挂)-哔哩哔哩1、poker ...
总结透视!pokemmo辅助器... 总结透视!pokemmo辅助器手机版下载!切实是有辅助神器(今日头条)-哔哩哔哩一、pokemmo辅...
解密透视!werplan外卦神... 解密透视!werplan外卦神器!总是真的是有辅助教程(有挂方法)-哔哩哔哩werplan外卦神器破...
普及透视!wepoker透视有... 普及透视!wepoker透视有吗!真是存在有辅助工具(有挂总结)-哔哩哔哩1、许多玩家不知道wepo...
解谜透视!哈糖大菠萝怎么开挂!... 解谜透视!哈糖大菠萝怎么开挂!一贯是有辅助插件(有挂辅助)-哔哩哔哩1、金币登录送、破产送、升级送、...
曝光透视!智星菠萝辅助!一贯一... 曝光透视!智星菠萝辅助!一贯一直都是有辅助方法(确实有挂)-哔哩哔哩暗藏猫腻,小编详细说明智星菠萝辅...
了解透视!newpoker脚本... 了解透视!newpoker脚本!总是一直都是有辅助攻略(有挂方针)-哔哩哔哩1、操作简单,无需new...
详情透视!智星德州辅助译码插件... 详情透视!智星德州辅助译码插件靠谱吗!一贯存在有辅助方法(存在有挂)-哔哩哔哩1、智星德州辅助译码插...