Skip to content

Commit

Permalink
Merge branch 'v4' of github.com:Authing/Guard into feat/v4-tenant-create
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaojingjing committed Jan 4, 2024
2 parents 70b5de6 + 3ee81bd commit d069d8c
Show file tree
Hide file tree
Showing 35 changed files with 892 additions and 123 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ node_modules
dist
lib
.angular

2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
"packages/*"
],
"useWorkspaces": true,
"version": "4.5.3"
"version": "4.5.7"
}
15 changes: 15 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions packages/guard-core-v4/example.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { Guard, User, GuardMode, GuardLocalConfig } from './src/index'
import { Guard, User, GuardLocalConfig } from './src/index'

import { React, render } from 'shim-react'

import * as facePlugin from 'face-api.js'

const App = () => {
const appId = '658bea8221ddf382ef4bb885'
const appId = '658e7ba8596b462d99912872'
// const deviceId = '6486be0f60e50cb92678a468' //如要使用必须使用开启元数据对的 用户池 测试

const config: Partial<GuardLocalConfig> = {
// mode: GuardMode.Modal,
// lang: 'en-US'
host: "http://11ying.authing.localhost:3000"
// lang: 'en-US',
host: 'http://1229.authing.localhost:3000'
}

const onLogin = (userInfo: User) => {
Expand Down
32 changes: 23 additions & 9 deletions packages/guard-core-v4/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/guard-core-v4/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@authing/guard-core",
"version": "4.5.3",
"version": "4.5.7",
"description": "Authing Guard Component for core codes, only be used to internal",
"types": "dist/typings/src/index.d.ts",
"files": [
Expand All @@ -18,6 +18,7 @@
"author": "https://github.com/authing",
"license": "MIT",
"dependencies": {
"@github/webauthn-json": "^2.1.1",
"authing-js-sdk": "^4.23.49",
"classnames": "^2.3.1",
"i18next": "^22.4.11",
Expand Down
61 changes: 35 additions & 26 deletions packages/guard-core-v4/scripts/webpack.dev.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,41 @@ const webpackBaseConfigFn = require('./webpack.base.config')
const { resolve } = require('./utils')

const reactVersion = '16'
const fs = require('fs')

module.exports = merge({}, webpackBaseConfigFn({
reactVersion
}), {
mode: 'development',
entry: resolve('example.tsx'),
output: {
filename: 'guard.min.js',
path: resolve(`dist/esm-react${reactVersion}`),
library: {
type: 'module'
module.exports = merge(
{},
webpackBaseConfigFn({
reactVersion
}),
{
mode: 'development',
entry: resolve('example.tsx'),
output: {
filename: 'guard.min.js',
path: resolve(`dist/esm-react${reactVersion}`),
library: {
type: 'module'
}
},
experiments: {
outputModule: true
},
resolve: {
fallback: {
fs: false,
crypto: false
}
},
devServer: {
// https: {
// key: fs.readFileSync('/Users/jayl/Code/authing/Guard/test.local.key'),
// cert: fs.readFileSync('/Users/jayl/Code/authing/Guard/test.local.crt'),
// },
// host: 'passkey.cj.local',
port: 8443,
hot: true,
open: true
}
},
experiments: {
outputModule: true
},
resolve: {
fallback: {
fs: false,
crypto: false
}
},
devServer: {
host: 'localhost',
port: 8090,
hot: true,
open: true
}
})
)
44 changes: 42 additions & 2 deletions packages/guard-core-v4/src/Guard/core/renderContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { useInitAppId } from '../../_utils/initAppId'

import { updateFlowHandle } from '../../_utils/flowHandleStorage'

import { ApplicationConfig } from '../../Type/application'
import { ApplicationConfig, LoginMethods } from '../../Type/application'

import { AuthenticationClient } from 'authing-js-sdk'

Expand All @@ -50,10 +50,14 @@ import { i18n } from '../../_utils/locales'

// hooks
import useMultipleAccounts from './hooks/useMultipleAccounts'

import { useMultipleTenant } from '../../_utils/tenant'

import Axios from 'axios'

const { useCallback, useEffect, useMemo, useReducer, useState } = React
import { getGuardDocument } from '../../_utils/guardDocument'

const { useCallback, useEffect, useMemo, useReducer, useState, useRef } = React

interface IBaseAction<T = string, P = any> {
type: T & string
Expand All @@ -77,6 +81,7 @@ export const RenderContext: React.FC<{
const [error, setError] = useState()
const [isAuthFlow, setIsAuthFlow] = useState(true)
const [i18nInit, setI18nInit] = useState(false)
const scriptNodes = useRef<Record<string, Element>>({})
const appId = useInitAppId(guardProps.appId, guardProps.authClient, setError)

const [defaultLanguageConfig, setDefaultLanguageConfig] = useState<Lang>()
Expand Down Expand Up @@ -224,6 +229,41 @@ export const RenderContext: React.FC<{
setCdnBase(publicConfig.cdnBase)
}, [appId, finallyConfig])

// 特殊脚本注入
useEffect(() => {
if (!publicConfig) {
return
}
const guardDocument = getGuardDocument()
// TODO: 脚本后续上传到 oss
if (
publicConfig.qrcodeTabsSettings?.[LoginMethods.DingTalkQrcode] &&
!scriptNodes.current?.dingtalk
) {
const dingdingScriptDom = document.createElement('script')
dingdingScriptDom.innerHTML =
'!function(e){var t={};function r(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)r.d(n,o,function(t){return e[t]}.bind(null,o));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=1382)}({1382:function(e,t){var r=function(e,t){var r=e.match(new RegExp("[?&]"+t+"=([^&]+)"));return r?r[1]:null};window.DTFrameLogin=function(e,t,n,o){var i,u=e.id&&document.getElementById(e.id)||null,c=document.createElement("iframe");t.client_id&&t.redirect_uri&&t.response_type&&t.scope?u?(u.innerHTML="",u.appendChild(c),c&&c.contentWindow&&c.contentWindow.postMessage&&window.addEventListener?(c.src="https://"+((i=t).isPre?"pre-login":"login")+".dingtalk.com/oauth2/auth?iframe=true&redirect_uri="+i.redirect_uri+"&response_type="+i.response_type+"&client_id="+i.client_id+"&scope="+i.scope+(i.prompt?"&prompt="+i.prompt:"")+(i.state?"&state="+i.state:"")+(i.org_type?"&org_type="+i.org_type:"")+(i.corpId?"&corpId="+i.corpId:"")+(i.exclusiveLogin?"&exclusiveLogin="+i.exclusiveLogin:"")+(i.exclusiveCorpId?"&exclusiveCorpId="+i.exclusiveCorpId:""),c.width=""+(e.width||300),c.height=""+(e.height||300),c.frameBorder="0",c.scrolling="no",window.addEventListener("message",(function(e){var t=e.data,i=e.origin;if(/login.dingtalk.com/.test(i)&&t)if(t.success&&t.redirectUrl){var u=t.redirectUrl,c=r(u,"authCode")||"",d=r(u,"state")||"",s=r(u,"error")||"";c?n&&n({redirectUrl:u,authCode:c,state:d}):o&&o(s)}else o&&o(t.errorMsg)}))):o&&o("Browser not support")):o&&o("Element not found"):o&&o("Missing parameters");return c;}}});'
guardDocument.body.appendChild(dingdingScriptDom)
scriptNodes.current = Object.assign(scriptNodes.current, {
dingtalk: dingdingScriptDom
})
}

if (
publicConfig.qrcodeTabsSettings?.[LoginMethods.WechatworkCorpQrconnect] &&
!scriptNodes.current?.weCom
) {
const weComScriptDom = document.createElement('script')
// weComScriptDom.innerHTML = `!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).WwLogin=t()}(this,(function(){"use strict";var e=["work.weixin.qq.com","tencent.com"],t={sso:"/wwopen/sso/qrConnect",tww:"/login/wwLogin/sso/qrConnect",native:"/native/sso/qrConnect",twxg:"/login/wwLogin/sso/qrConnect"},n="1.2.7";return function(){function o(e){this.options=e,this.options=e,this.createFrame()}return o.prototype.destroyed=function(){console.log("WwLogin had destroyed."),window.removeEventListener("message",this.onPostMessage)},o.prototype.getUrl=function(e){var o=[];Object.keys(e).forEach((function(t){var n=e[t];[void 0,null].indexOf(n)>-1||-1!==["string","number","boolean"].indexOf(typeof n)&&"id"!==t&&o.push("".concat(t,"=").concat(n))})),o.push("version=".concat(n)),o.push("login_type=jssdk");var s=t[e.business_type||"sso"];if(!s)throw new Error("Argument business_type not match. Current version is ".concat(n,"."));var i="https://open.work.weixin.qq.com";return/tencent\.com$/.test(window.location.host)&&(i="https://open.wecom.tencent.com"),"".concat(i).concat(s,"?").concat(o.join("&"))},o.prototype.createFrame=function(){var e=this;if(this.options.is_mobile)window.location.href=this.getUrl(this.options);else{this.frame=document.createElement("iframe");var t=document.getElementById(this.options.id);this.frame.src=this.getUrl(this.options),this.frame.frameBorder="0",this.frame.allowTransparency="true",this.frame.scrolling="no",this.frame.width="158px",this.frame.height="158px",t.innerHTML="",t.appendChild(this.frame),this.frame.onload=function(){e.frame.contentWindow.postMessage&&window.addEventListener&&(window.addEventListener("message",e.onPostMessage),e.frame.contentWindow.postMessage("ask_usePostMessage","*"))}}},o.prototype.onPostMessage=function(t){if(e.filter((function(e){return new RegExp("".concat(e,"$")).test(t.origin)})).length){var n=t.data;if(n&&"string"==typeof n&&/^http/.test(n)){var b = document.createElement('iframe');b.src = n; b.style.display = 'none';document.body.appendChild(b)}}},o}()}));`
weComScriptDom.innerHTML =
'!(function(e,t){"object"==typeof exports&&"undefined"!=typeof module?(module.exports=t()):"function"==typeof define&&define.amd?define(t):((e="undefined"!=typeof globalThis?globalThis:e||self).WwLogin=t())})(this,function(){"use strict";var e=["work.weixin.qq.com","tencent.com"],t={sso:"/wwopen/sso/qrConnect",tww:"/login/wwLogin/sso/qrConnect",native:"/native/sso/qrConnect",twxg:"/login/wwLogin/sso/qrConnect"},n="1.2.7";return(function(){function o(e){(this.options=e),(this.options=e),this.createFrame()}return((o.prototype.destroyed=function(){console.log("WwLogin had destroyed."),window.removeEventListener("message",this.onPostMessage)}),(o.prototype.getUrl=function(e){var o=[];Object.keys(e).forEach(function(t){var n=e[t];[void 0,null].indexOf(n)>-1||(-1!==["string","number","boolean"].indexOf(typeof n)&&"id"!==t&&o.push("".concat(t,"=").concat(n)))}),o.push("version=".concat(n)),o.push("login_type=jssdk");var s=t[e.business_type||"sso"];if(!s)throw new Error("Argument business_type not match. Current version is ".concat(n,"."));var i="https://open.work.weixin.qq.com";return(/tencent.com$/.test(window.location.host)&&(i="https://open.wecom.tencent.com"),"".concat(i).concat(s,"?").concat(o.join("&")))}),(o.prototype.createFrame=function(){var e=this;if(this.options.is_mobile)window.location.href=this.getUrl(this.options);else{this.frame=document.createElement("iframe");var t=document.getElementById(this.options.id);(this.frame.src=this.getUrl(this.options)),(this.frame.frameBorder="0"),(this.frame.allowTransparency="true"),(this.frame.scrolling="no"),(this.frame.width="100%"),(this.frame.height="194px"),(t.innerHTML=""),t.appendChild(this.frame),(this.frame.onload=function(){e.frame.contentWindow.postMessage&&window.addEventListener&&e.frame.contentWindow.postMessage("ask_usePostMessage","*")})}}),o)})()});'
guardDocument.body.appendChild(weComScriptDom)
scriptNodes.current = Object.assign(scriptNodes.current, {
weCom: weComScriptDom
})
}
}, [publicConfig])

// I18n
useEffect(() => {
if (guardPageConfig && publicConfig && defaultMergedConfig) {
Expand Down
Loading

0 comments on commit d069d8c

Please sign in to comment.