在这呆了几天。我正在我的 angular/nodejs 应用程序上制作一个登录表单。bc-api 能够验证用户/密码。现在,我需要允许客户使用 sso 进入商店,但生成的 jwt 不起作用。我在下面的尝试......我正在寻找故障排除技巧。
var jwt = require('jwt-simple');
function decode_utf8(s) {
return decodeURIComponent(escape(s));
}
function get_token(req, data) {
let uid = req.id;
let time = Math.round((new Date()).getTime() / 1000);
let payload = {
"iss": app.clientId,
// "iat": Math.floor(new Date() / 1000),
"iat": time,
"jti": uid+"-"+time,
"operation": "customer_login",
"store_hash": app.storeHash,
"customer_id": uid,
"redirect_to": app.entry_url
}
let token = jwt.encode(payload, app.secret, 'HS512');
token = decode_utf8(token);
let sso_url = {sso_url: `${app.entry_url}/login/token/${token}`}
return sso_url
}
Run Code Online (Sandbox Code Playgroud)
payload 决心{
"iss": "hm6ntr11uikz****l3j2o662eurac9w",
"iat": 1529512418,
"jti": "1-1529512418",
"operation": "customer_login",
"store_hash": "2bihpr2wvz",
"customer_id": "1",
"redirect_to": "https://store-2bihpr2wvz.mybigcommerce.com"
}
Run Code Online (Sandbox Code Playgroud)
sso_urlhttps://store-2bihpr2wvz.mybigcommerce.com/login/token/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJpc3MiOiJobTZudHIxMXVpa3oxMXpkbDNqMm82NjJldXJhYzl3IiwiaWF0IjoxNTI5NTEyNDE4LCJqdGkiOiIxLTE1Mjk1MTI0MTgiLCJvcGVyYXRpb24iOiJjdXN0b21lcl9sb2dpbiIsInN0b3JlX2hhc2giOiIyYmlocHIyd3Z6IiwiY3VzdG9tZXJfaWQiOiIxIiwicmVkaXJlY3RfdG8iOiJodHRwczovL3N0b3JlLTJiaWhwcjJ3dnoubXliaWdjb21tZXJjZS5jb20ifQ.vaeVTw4NjvX6AAPChgdXgMhm9b1W5B2QEwi4sJ6jz9KsKalqTqleijjRKs8jZP8jdQxC4ofYX5W0wYPMTquxQQ
Run Code Online (Sandbox Code Playgroud)
我正在使用 nodejs express ...我的 bc 应用程序的秘密和 clientId 正在上面使用,它们适用于其他几个 bc-api 任务。我的应用程序已在 bc admin 上安装并通过身份验证。用于执行上述操作的应用程序在本地主机上运行,但我也尝试过在线 https(结果相同)。
我想我的商店管理员中可能有一些不正确的配置,但还没有找到任何可以改变的东西。
小智 6
我在 jwt.io 上解码了你的 JWT,我得到了这个:
标题:
{
"typ": "JWT",
"alg": "HS512"
}
Run Code Online (Sandbox Code Playgroud)
这里至少有一个问题
根据文档,BC 需要 HS256 作为算法
https://developer.bigcommerce.com/api/v3/storefront.html#/introduction/customer-login-api
身体:
{
"iss": "hm6ntr11uikz11zdl3j2o662eurac9w",
"iat": 1529512418,
"jti": "1-1529512418",
"operation": "customer_login",
"store_hash": "2bihpr2wvz",
"customer_id": "1",
"redirect_to": "https://store-2bihpr2wvz.mybigcommerce.com"
}
Run Code Online (Sandbox Code Playgroud)
这里的问题:
| 归档时间: |
|
| 查看次数: |
469 次 |
| 最近记录: |