Jonny Huang
node 8 nodejs ssl handshake error
const https = require('https');
export async function GetUserinfo(Token) {
console.log(process.env["NODE_TLS_REJECT_UNAUTHORIZED"])
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
console.log(process.env["NODE_TLS_REJECT_UNAUTHORIZED"])
const baseURL = 'https://openid.hydra:9001';
const userinfoURL = '/userinfo';
axios({
method: 'get',
headers: {
'Authorization': 'Bearer ' + Token,
'accept': 'application/json'
},
httpsAgent: new https.Agent({
rejectUnauthorized: false,
ecdhCurve: 'auto'
}),
url: userinfoURL,
baseURL: baseURL,
responseType: 'json'
}).then(function (response) {
process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;
No Need, No meanError: self signed certificate
Answer: rejectUnauthorized: false,
HTTPs requests to API fail: 'sslv3 alert handshake failure
Answer: ecdhCurve: 'auto'
Ory Hydra Authorization Code Exchange => access token Use openid-client
https://github.com/panva/node-openid-client/tree/v2.x
So watch https://github.com/panva/node-openid-client/tree/v2.x
node.js package use "openid-client": "2.5.0",
https://github.com/panva/node-openid-client/blob/f1b4282ac50f7e15fc195f66bf76409af4ec4b6b/lib/client.js
see if (params.code) { Can know use grant
https://github.com/panva/node-openid-client/tree/v2.x#custom-token-endpoint-grants
Important! WARNING: Node.js 12 or higher is required for openid-client@3 and above. For older Node.js versions use openid-client@2.
So watch https://github.com/panva/node-openid-client/tree/v2.x
node.js package use "openid-client": "2.5.0",
client.authorizationCallback have bug, nonce mismatch always have this error even see https://github.com/panva/node-openid-client/issues/150
Correct way
https://github.com/panva/node-openid-client/blob/f1b4282ac50f7e15fc195f66bf76409af4ec4b6b/lib/client.js
see if (params.code) { Can know use grant
https://github.com/panva/node-openid-client/tree/v2.x#custom-token-endpoint-grants
const hydraconfig= {
"oidurl": "https://openid.hydra:9001",
"redirectUri": "https://t.tt:9010/callback",
"clientid": "auth-code-client",
"clientsecretid": "secret"
}
//openid-client================
const { Issuer } = require('openid-client')
const hydraIssuer = await Issuer.discover(hydraconfig.oidurl) // => Promise
.then(function (hydradiscoverIssuer) {
console.log('Discovered issuer %s %O', hydradiscoverIssuer.issuer, hydradiscoverIssuer.metadata);
return hydradiscoverIssuer
});
const client = new hydraIssuer.Client({
client_id: hydraconfig.clientid,
client_secret: hydraconfig.clientsecretid
});
var tokenset = await client.grant({
grant_type: 'authorization_code',
code: code,
redirect_uri: hydraconfig.redirectUri,
code_verifier: '', //No value, because real use in Hydra login-consent. Not use client.authorizationUrl or client.authorizationPost
});
console.log(tokenset)
javascript console.log object
console.log('show value string, object %s %O', var.string, var.object);
Ory Hydra Authorization Code Exchange => access token
Before posts about Hydra get access token is use golang HydraOauthConfig.Exchange(ctx, code). This is easy way. But on front website like vue or other framework how to get access token.
https://github.com/ory/hydra/issues/631
Not Authorization: Bearer
YXV0aC1jb2RlLWNsaWVudDpzZWNyZXQ= => auth-code-client:secret
example: https://t.tt:9010/callback?code=cuNw76aEuckIJJyVssk2LJvqdLXffT-8Kx1s0tYFt6Y.v0Dxc2_yT9ga8c2moKx0fDbwRFVgwryAt5BJM7lOJlM&scope=openid%20offline&state=gczxkznmjkrksgytsemvwgkf
If code have error message, you need check before any step have incorrect.
https://www.ory.sh/docs/hydra/sdk/api#the-oauth-20-token-endpoint
You need to sure grant_type=authorization_code Not other options.
But SDK Document No any options example. Only suggestion you use lib. So you need to try many.
like follow
https://www.oauth.com/oauth2-servers/pkce/authorization-code-exchange/
https://community.ory.sh/t/how-configure-grant-implicit-flow/411/14
https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce
https://github.com/oauthjs/express-oauth-server/issues/55
https://www.jianshu.com/p/5cf2b7a45b75
http://www.passportjs.org/docs/oauth/
Then try out a ways.
OK. Mark is not important Required.
Use REST Client to test
POST https://openid.hydra:9001/oauth2/token
Authorization: Basic YXV0aC1jb2RlLWNsaWVudDpzZWNyZXQ=
Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code
&code=cuNw76aEuckIJJyVssk2LJvqdLXffT-8Kx1s0tYFt6Y.v0Dxc2_yT9ga8c2moKx0fDbwRFVgwryAt5BJM7lOJlM
#&redirect_uri=https://certfront/oid/test/callback
#&scope=openid,offline
#&client_id=auth-code-client
#&code_verifier=
#&state=gczxkznmjkrksgytsemvwgkf
Import is: Authorization: Basic
https://github.com/ory/hydra/issues/631
Not Authorization: Bearer
base64(urlencode(client_id):urlencode(client_secret))
YXV0aC1jb2RlLWNsaWVudDpzZWNyZXQ= => auth-code-client:secret
code is callback code. When you login-consent finish step then callback to your set callback URL. Watch URL inside have code=
example: https://t.tt:9010/callback?code=cuNw76aEuckIJJyVssk2LJvqdLXffT-8Kx1s0tYFt6Y.v0Dxc2_yT9ga8c2moKx0fDbwRFVgwryAt5BJM7lOJlM&scope=openid%20offline&state=gczxkznmjkrksgytsemvwgkf
If code have error message, you need check before any step have incorrect.
In Ory Hydra get access token is not like sdk document
https://www.ory.sh/docs/hydra/sdk/api#the-oauth-20-token-endpoint
You need to sure grant_type=authorization_code Not other options.
But SDK Document No any options example. Only suggestion you use lib. So you need to try many.
like follow
https://www.oauth.com/oauth2-servers/pkce/authorization-code-exchange/
https://community.ory.sh/t/how-configure-grant-implicit-flow/411/14
https://auth0.com/docs/api-auth/tutorials/authorization-code-grant-pkce
https://github.com/oauthjs/express-oauth-server/issues/55
https://www.jianshu.com/p/5cf2b7a45b75
http://www.passportjs.org/docs/oauth/
Then try out a ways.
OK. Mark is not important Required.
#&redirect_uri=https://certfront/oid/test/callback
#&scope=openid,offline
#&client_id=auth-code-client
#&code_verifier=
#&state=gczxkznmjkrksgytsemvwgkf
oauth2 nodejs
https://peach.ebu.io/technical/tutorials/tuto-oauth2-client/
https://www.pveller.com/oauth2-with-passport-10-steps-recipe/
http://www.hitotec.com/authentification-oauth-avec-passportjs-pour-une-api-rest/
https://www.shangyang.me/2018/03/11/javascript-nodejs-passport-04-deepinto-oauth2-authenticate-process/
https://blog.yorkxin.org/2013/09/30/oauth2-4-1-auth-code-grant-flow.html
https://www.pveller.com/oauth2-with-passport-10-steps-recipe/
http://www.hitotec.com/authentification-oauth-avec-passportjs-pour-une-api-rest/
https://www.shangyang.me/2018/03/11/javascript-nodejs-passport-04-deepinto-oauth2-authenticate-process/
https://blog.yorkxin.org/2013/09/30/oauth2-4-1-auth-code-grant-flow.html
[轉]如何使用 OpenSSL 建立開發測試用途的自簽憑證 (Self-Signed Certificate)
https://blog.miniasp.com/post/2019/02/25/Creating-Self-signed-Certificate-using-OpenSSL
目前這個方式比較靠普
建立 ssl.conf 設定檔
目前這個方式比較靠普
建立 ssl.conf 設定檔
[req]
prompt = no
default_md = sha256
default_bits = 2048
distinguished_name = dn
x509_extensions = v3_req
[dn]
C = TW
ST = Taiwan
L = Taipei
O = Duotify Inc.
OU = IT Department
emailAddress = admin@example.com
CN = localhost
[v3_req]
subjectAltName = @alt_names
[alt_names]
DNS.1 = *.localhost
DNS.2 = localhost
DNS.3 = 192.168.2.100
openssl req -x509 -new -nodes -sha256 -utf8 -days 3650 -newkey rsa:2048 -keyout server.key -out server.crt -config ssl.conf
oauth2 nodejs vue
https://www.ory.sh/docs/hydra/integration#interacting-with-oauth-20
https://github.com/lelylan/simple-oauth2
https://www.jianshu.com/p/5cf2b7a45b75
https://github.com/lelylan/simple-oauth2
https://www.jianshu.com/p/5cf2b7a45b75
vue 3 image assets
Vue template Code
src/ooxx/ooxx/xx.vue
assets
File location:assets/img/tt.png
OK
Code:img src='@/assets/img/tt.png'
Become:
img src="/img/tt.f3b936ef.png"
Failed
Code:img src='@/img/nchcbclab.png'
img src='assets/img/tt.png'
img src='./assets/img/tt.png'
img src='../assets/img/tt.png'
img src="require('assets/img/tt.png') "
img src="require('./assets/img/tt.png') "
img src="require('../assets/img/tt.png') "
public
File location:public/img/tt.png
OK
Code:img src= '/img/nchcbclab.png'
Become:
img src= '/img/nchcbclab.png'
Failed
Code:img src= 'img/nchcbclab.png'
img src= 'public/img/nchcbclab.png'
img src='/public/img/nchcbclab.png'
vue 3 index.html
old vue index.html just copy to public directory.
If public don't have index.hmtl, be craeted by run "npm run serve". But public don't have index.html.
Only "npm run build" create index.html in dist driectory.
You delete all project index.html. This time still can run "npm run serve". Watch Website source code <title>Vue App</title>
Then put your custome into public directory then <title>Custome App ooxxooxx </title>
If public don't have index.hmtl, be craeted by run "npm run serve". But public don't have index.html.
Only "npm run build" create index.html in dist driectory.
More easy understand way:
You delete all project index.html. This time still can run "npm run serve". Watch Website source code <title>Vue App</title>
Then put your custome into public directory then <title>Custome App ooxxooxx </title>
vue babel 7
https://github.com/storybookjs/storybook/issues/5298
https://github.com/webpack/webpack/issues/4039
https://github.com/gmfe/Think/issues/67
Full code
https://github.com/webpack/webpack/issues/4039
https://github.com/gmfe/Think/issues/67
Cannot assign to read only property 'exports' of object '#<Object>'
babel.config.js
'sourceType': 'unambiguous', // 自动推断编译的模块类型(cjs,es6)
'ignore': [/@babel[/\\]runtime/], // 忽略 @babel/runtime
Full code
module.exports = {
'sourceType': 'unambiguous', // 自动推断编译的模块类型(cjs,es6)
'ignore': [/@babel[/\\]runtime/], // 忽略 @babel/runtime
presets: [
'@vue/app'
]
}
vue 3 vue-cli-service serve vue.config.js package.json docker
"serve": "vue-cli-service serve",
Some page modify vue-cli-service serve --host 0.0.0.0 --port 8978
This may in docker failed.
So some page modify vue.config.js
Use public is Failed!!
Use host port is Correct!!
PS:
.Put eslint is maybe get some eslint error, not about host ip port.
.disableHostCheck can remove for try by yourself env.
Some page modify vue-cli-service serve --host 0.0.0.0 --port 8978
This may in docker failed.
Error: listen EADDRNOTAVAIL: address not available
So some page modify vue.config.js
Use public is Failed!!
devServer: {
public: '0.0.0.0:80',
disableHostCheck: true,
}
Use host port is Correct!!
module.exports = {
chainWebpack: config => {
config.module.rules.delete('eslint');
},
devServer: {
host: '0.0.0.0',
port: '80',
//public: '0.0.0.0:80', //無效
disableHostCheck: true,
}
}
PS:
.Put eslint is maybe get some eslint error, not about host ip port.
.disableHostCheck can remove for try by yourself env.
Mirror Your Traffic Duplicate
goreplay
https://github.com/buger/goreplay
tcpcopy
https://github.com/session-replay-tools/tcpcopy
teeproxy
https://github.com/chrislusf/teeproxy
duplicator
https://github.com/agnoster/duplicator
goduplicator
https://github.com/mkevac/goduplicator
nginx mirror
haproxy mirror
https://github.com/buger/goreplay
tcpcopy
https://github.com/session-replay-tools/tcpcopy
teeproxy
https://github.com/chrislusf/teeproxy
duplicator
https://github.com/agnoster/duplicator
goduplicator
https://github.com/mkevac/goduplicator
nginx mirror
haproxy mirror
[轉]How to Mirror Your Traffic with Nginx
https://www.serverlab.ca/tutorials/linux/web-servers-linux/how-to-mirror-your-traffic-with-nginx/
ipfs
https://www.fil.club/view/77.html
端口8080是HTTP网关,它允许您使用浏览器查询ipfs数据(请参阅此示例)
端口4001是IPFS用于与其他节点通信的群集端口,端口5001用于本地API。
我们5001只会绑定127.0.0.1因为它不应该暴露给外界。
我们已经安装了数据和分段卷。
该data卷用于存储IPFS本地存储(配置和数据库),并且
staging是一个可用于暂存文件以供命令行使用的目录(例如ipfs add)。
如果您只使用API,则可以省略暂存目录卷。当然,随意将这些目录放在除了之外的其他地方/tmp。
端口8080是HTTP网关,它允许您使用浏览器查询ipfs数据(请参阅此示例)
端口4001是IPFS用于与其他节点通信的群集端口,端口5001用于本地API。
我们5001只会绑定127.0.0.1因为它不应该暴露给外界。
我们已经安装了数据和分段卷。
该data卷用于存储IPFS本地存储(配置和数据库),并且
staging是一个可用于暂存文件以供命令行使用的目录(例如ipfs add)。
如果您只使用API,则可以省略暂存目录卷。当然,随意将这些目录放在除了之外的其他地方/tmp。
[轉]用Go来做以太坊开发
https://github.com/miguelmota/ethereum-development-with-go-book
https://goethereumbook.org/zh/
https://goethereumbook.org/zh/
ethereum explorer
https://github.com/gobitfly/etherchain-light
https://github.com/gobitfly/erc20-explorer
https://github.com/carsenk/explorer
https://github.com/Capgemini-AIE/ethereum-docker/tree/master/monitored-geth-client
https://github.com/cubedro/eth-net-intelligence-api
https://github.com/cubedro/eth-netstats
Browse blocks and transactions
It's nice to have some simple analogue of Etherscan for your local chain browsing. It will be useful to examine transactions, balances, blocks and etc. It appeared that it is quite difficult to find an open-source good solution for geth. After several tries I found an acceptable solution called ETHExplorer V2. Clone it into explorer-v2 folder. To Dockerize it I had to make 2 changes. First create a Dockerfile
And change start script in package.json to "start": "http-server ./app -a 0.0.0.0 -p 8000 -c-1". This is required to allow connections to explorer from any IP (outside docker). Next we should create a service for explorer
https://github.com/gobitfly/erc20-explorer
https://github.com/carsenk/explorer
https://github.com/Capgemini-AIE/ethereum-docker/tree/master/monitored-geth-client
https://github.com/cubedro/eth-net-intelligence-api
https://github.com/cubedro/eth-netstats
Browse blocks and transactions
It's nice to have some simple analogue of Etherscan for your local chain browsing. It will be useful to examine transactions, balances, blocks and etc. It appeared that it is quite difficult to find an open-source good solution for geth. After several tries I found an acceptable solution called ETHExplorer V2. Clone it into explorer-v2 folder. To Dockerize it I had to make 2 changes. First create a Dockerfile
# ./explorer-v2/Dockerfile
FROM node:6
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN npm install && \
node_modules/.bin/bower install --allow-root
And change start script in package.json to "start": "http-server ./app -a 0.0.0.0 -p 8000 -c-1". This is required to allow connections to explorer from any IP (outside docker). Next we should create a service for explorer
./docker-compose.yml
# ...
explorer:
build: explorer-v2
container_name: explorer
command: npm start
ports:
- "8000:8000"
訂閱:
文章 (Atom)


