Skip to content

Commit

Permalink
增加微博社交登录(参考连接:https://github.com/vergnes/spring-social-weibo
Browse files Browse the repository at this point in the history
  • Loading branch information
longfeizheng committed Jan 12, 2018
1 parent e07a808 commit edf359a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-web</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.social</groupId>
<artifactId>spring-social-weibo</artifactId>
<version>1.0.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,16 @@ public interface SecurityConstants {
*/
String DEFAULT_SOCIAL_QQ_APP_SECRET = "1d958787a87559bad371c0a9e26eef61";

/**
* weibo appID
*/
String DEFAULT_SOCIAL_WEIBO_APP_ID = "491608476";

/**
* weibo appsECRET
*/
String DEFAULT_SOCIAL_WEIBO_APP_SECRET = "b2dd0d4199ddc9d64e75d9dd6007ca82";

/**
*自定义社交social拦截地址 默认/auth (SocialAuthenticationFilter)
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cn.merryyou.logback.social.weibo.config;

import cn.merryyou.logback.properties.SecurityConstants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.social.SocialAutoConfigurerAdapter;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.connect.ConnectionFactory;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.ConnectionSignUp;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
import org.springframework.social.weibo.connect.WeiboConnectionFactory;

import javax.sql.DataSource;


/**
* Created on 2018/1/12.
*
* @author zlf
* @since 1.0
*/
@Configuration
public class WeiboAuthConfig extends SocialAutoConfigurerAdapter {
@Autowired
private DataSource dataSource;

@Autowired
private ConnectionSignUp myConnectionSignUp;

@Override
protected ConnectionFactory<?> createConnectionFactory() {
return new WeiboConnectionFactory(SecurityConstants.DEFAULT_SOCIAL_WEIBO_APP_ID, SecurityConstants.DEFAULT_SOCIAL_WEIBO_APP_SECRET);
}

@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(dataSource,
connectionFactoryLocator, Encryptors.noOpText());
if (myConnectionSignUp != null) {
repository.setConnectionSignUp(myConnectionSignUp);
}
return repository;
}
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/ftl/login.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
<div class="right other_right">
<a href="/login/qq"><i class="fa fa-qq fa-2x"></i></a>
<a href="/login/weixin"><i class="fa fa-weixin fa-2x"></i></a>
<a href="#"><i class="fa fa-weibo fa-2x"></i></a>
<a href="/login/weibo"><i class="fa fa-weibo fa-2x"></i></a>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/ftl/register.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
<div class="right other_right">
<a href="/login/qq"><i class="fa fa-qq fa-2x"></i></a>
<a href="/login/weixin"><i class="fa fa-weixin fa-2x"></i></a>
<a href="#"><i class="fa fa-weibo fa-2x"></i></a>
<a href="/login/weibo"><i class="fa fa-weibo fa-2x"></i></a>
</div>
</div>
</div>
Expand Down

0 comments on commit edf359a

Please sign in to comment.