-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from Authing/dev-local
chore: add webpack.dev.config.js, enable development in localhost
- Loading branch information
Showing
5 changed files
with
1,365 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { AuthingSSO } from './index' | ||
|
||
const auth = new AuthingSSO({ | ||
appId: 'AUTHING_APP_ID', | ||
|
||
// SSO 应用面板地址 | ||
origin: 'https://{SSO 应用面板地址}.authing.cn', | ||
|
||
// 应用登录回调 URL | ||
redirectUri: 'http://localhost:3001/login/callback' | ||
}) | ||
|
||
window.onload = async function () { | ||
let res = await auth.trackSession() | ||
if (res.session !== null) { | ||
document.getElementById('h1-user-info').style.display = 'block' | ||
document.getElementById('user-info').innerHTML = JSON.stringify(res.userInfo, null, 4) | ||
document.getElementById('btn-logout').style.display = 'inline' | ||
} else { | ||
document.getElementById('h1-login').style.display = 'block' | ||
document.getElementById('btn-login').style.display = 'inline' | ||
} | ||
} | ||
|
||
document.getElementById('btn-login').addEventListener('click', function () { | ||
auth.login({ | ||
scope: 'openid profile email phone', | ||
responseMode: 'fragment', | ||
responseType: 'code token', | ||
state: Math.random().toString(), | ||
nonce: Math.random().toString() | ||
}) | ||
}) | ||
|
||
document.getElementById('btn-logout').addEventListener('click', function () { | ||
auth.logout().then((res) => { | ||
alert(JSON.stringify(res)) | ||
location.reload() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>AuthingSSO DEV</title> | ||
</head> | ||
|
||
<body> | ||
<h1 id="h1-login" style="display: none;">请登录</h1> | ||
<input type="button" value="登录" id="btn-login" style="display: none;" /> | ||
<h1 id="h1-user-info" style="display: none;">用户信息</h1> | ||
<input type="button" value="登出" id="btn-logout" style="display: none;" /> | ||
<pre id="user-info"></pre> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
const path = require('path') | ||
|
||
const HtmlWebpackPlugin = require('html-webpack-plugin') | ||
|
||
const resolve = function (...args) { | ||
return path.resolve(__dirname, ...args) | ||
} | ||
|
||
module.exports = { | ||
mode: 'development', | ||
entry: resolve('./src/example.ts'), | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(js|mjs|jsx|ts|tsx)$/, | ||
exclude: /node_modules/, | ||
use: { | ||
loader: 'babel-loader', | ||
options: { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
chrome: '49', | ||
ie: '11', | ||
}, | ||
useBuiltIns: 'usage', | ||
corejs: { | ||
version: 3, // 使用core-js@3 | ||
proposals: true, | ||
}, | ||
}, | ||
], | ||
'@babel/preset-typescript', | ||
], | ||
plugins: [ | ||
'@babel/plugin-transform-runtime', | ||
'@babel/plugin-transform-arrow-functions', | ||
], | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.ts', '.js'], | ||
}, | ||
plugins: [ | ||
new HtmlWebpackPlugin({ | ||
template: resolve('./src/index.html'), | ||
filename: 'index.html' | ||
}) | ||
], | ||
devServer: { | ||
host: 'localhost', | ||
port: 3004, | ||
hot: true, | ||
open: true | ||
} | ||
} |
Oops, something went wrong.