Keycloak integrated wechat login to solve the problem of domestic wechat integration

Time:2021-7-18

I read the article on wechat integration keycloak written in China and used it. However, I use the keycloak deployed by JBoss. After using his package, there will be a problem that the class cannot be found. Later, I found a lot of materials, most of which are foreign. Today, I finally found a solution to this problem. First, you use shade and assembly to package, It’s impossible to type in the missing packages, because the project deployed by someone else already has your keyclock packages, so different classloads will load the same class, and the result is that the same class will be loadednot a subtypeIt’s a matter of time.

summary

reference resources:https://stackoverflow.com/questions/57778240/noclassdeffounderror-in-a-provider-jar-when-using-a-class-from-org-keycloak-auth

A dependency package needs to be injected into manifest. MF

org.apache.maven.plugins
        maven-jar-plugin
        
            
                
                    org.keycloak.keycloak-services

Meta-inf / manifest.mf generated
1

Second version package and version

The version of keycloak used in your Weixin should be the same as that of the server, because your package is to be deployed to other people’s servers. The server and I use 11.0.2

org.keycloak
            keycloak-core
            provided
            ${keycloak.version}
        
        
            org.keycloak
            keycloak-server-spi
            provided
            ${keycloak.version}
        
        
            org.keycloak
            keycloak-server-spi-private
            provided
            ${keycloak.version}
        
        
            org.keycloak
            keycloak-services
            provided
            ${keycloak.version}

Three, two classes, one configuration

The specific code can imitate his GitHub implementation

public class WeiXinIdentityProvider extends AbstractOAuth2IdentityProvider
        implements SocialIdentityProvider {}

public class WeiXinIdentityProviderFactory extends AbstractIdentityProviderFactory
        implements SocialIdentityProviderFactory {}

Add the file org.keycloak.broker.social.socialidentityproviderfactory to meta-inf.services. Its contents are as follows: an implementation class and a factory class

com.test.weixin.WeiXinIdentityProviderFactory

IV. deployment

The deployment plug-in directory of JBoss / keycloak is/opt/jboss/keycloak/standalone/deployments

docker cp ./keycloak-services-social-weixin.jar keycloak:/opt/jboss/keycloak/standalone/deployments &&
docker cp ./templates/realm-identity-provider-weixin.html  keycloak:/opt/jboss/keycloak/themes/base/admin/resources/partials  &&
docker cp ./templates/realm-identity-provider-weixin-ext.html  keycloak:/opt/jboss/keycloak/themes/base/admin/resources/partials

Your program does not need to restart, it supports hot deployment!