Skip to content

Commit

Permalink
feat(UNI-208): keycloak init with options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff-Tian committed Mar 23, 2024
1 parent 52e2288 commit 281e3be
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.keycloak</groupId>
<artifactId>keycloak-services-social-weixin</artifactId>
<packaging>jar</packaging>
<version>0.5.26</version>
<version>0.5.27</version>

<name>Keycloak Services Social WeiXin</name>
<description>Keycloak 微信登录插件,支持 PC 端扫码登录、关注公众号即登录、手机微信等登录方式。</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public Response mpQrUrl(@QueryParam("ticket") String ticket, @QueryParam("qr-cod

var host = session.getContext().getUri().getBaseUri().toString();
var realmName = session.getContext().getRealm().getName();
var accountRedirectUri = host + "/realms/" + realmName + "/account";

logger.info(String.format("host is %s, realmName is %s", host, realmName));

Expand All @@ -72,7 +73,7 @@ public Response mpQrUrl(@QueryParam("ticket") String ticket, @QueryParam("qr-cod
<img src="%s" alt="%s">
<p></p>
<p><button id="login-by-username-password" onclick="keycloak.login({ idpHint:'username' });" type="button">使用密码登录</button></p>
<p><button id="login-by-username-password" onclick="keycloak.login({ idpHint: 'username', redirectUri: '%s' });" type="button">使用密码登录</button></p>
</div>
<script type="text/javascript">
async function fetchQrScanStatus() {
Expand All @@ -99,15 +100,16 @@ async function fetchQrScanStatus() {
const keycloak = new Keycloak({
url: '%s',
realm: '%s',
clientId: 'account-console'
clientId: 'account-console',
redirectUri: '%s'
});
keycloak.init();
keycloak.init({onLoad: 'check-sso', pkceMethod: 'S256', promiseType: 'native'});
</script>
</body>
</html>
""";

String htmlContent = String.format(template, qrCodeUrl, ticket, ticket, redirectUri, state, host, realmName);
String htmlContent = String.format(template, qrCodeUrl, ticket, accountRedirectUri, ticket, redirectUri, state, host, realmName, accountRedirectUri);

// 返回包含HTML内容的响应
return Response.ok(htmlContent, MediaType.TEXT_HTML_TYPE).build();
Expand Down

0 comments on commit 281e3be

Please sign in to comment.