校对:soup
在您的 Javascript 应用程序中接受 MitID、NemID、瑞典银行ID、挪威银行ID 和其他电子ID供应商的登录 @criipto/auth-js。 。 。 .
指数
安装
npm install --save @criipto/auth-js
使用量
import CriiptoAuth from "@criipto/auth-js";
import "@criipto/auth-js/index.css";
var criiptoAuth = new CriiptoAuth({
domain: "{YOUR_CRIIPTO_DOMAIN}",
clientID: "{YOUR_CRIIPTO_APPLICATION_ID}",
store: sessionStorage,
});
criiptoAuth.popup.authorize({
width: 300,
height: 400,
redirectUri: "http://localhost:8000/example/popup-callback.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
});
criiptoAuth.redirect.authorize({
redirectUri: "http://localhost:8000/example/index.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
});
认证
初始化/构建者
var criiptoAuth = new CriiptoAuth({
domain: "{YOUR_CRIIPTO_DOMAIN}",
clientID: "{YOUR_CRIIPTO_APPLICATION_ID}",
store: sessionStorage,
});
var criiptoAuth = new CriiptoAuth({
domain: "{YOUR_CRIIPTO_DOMAIN}",
clientID: "{YOUR_CRIIPTO_APPLICATION_ID}",
store: sessionStorage,
redirectUri: "http://localhost:8000/example/index.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
});
参数:
- 域( 需要, 字符串): 您的 Criipto 应用程序所属域, 例如
example.criipto.id。 。 。 . - 客户端ID( 需要, 字符串): Criipto 应用程序的客户端 ID/ realm.
- 额外授权参数: 见 授权参数
授权参数
所有授权方法,如 criiptoAuth.popup.authorize, (中文(简体) ), criiptoAuth.redirect.authorize 财务报告和审定财务报表 criiptoAuth.authorizeResponsive 使用一组授权参数。 这些授权参数也可以默认情况下通过 CriiptoAuth 建筑师.
- 重定向Uri (字符串): Criipto 将随认证成功或失败的结果调回的 URL 。 它必须在您的 Criipto 应用程序设置中的“ 召回 URL” 中被白列.
- 字符串(字符串): 用于认证的 EID, 如
urn:grn:authn:dk:mitid:substantial中,可找到可接受值列表https://{YOUR_CRIIPTO_DOMAIN}/.well-known/openid-configuration
授权响应
criiptoAuth.authorizeResponsive({
"(min-width: 768px)": {
via: "popup",
redirectUri: "http://localhost:8000/example/popup-callback.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
width: 320,
height: 460,
},
"(max-width: 767px)": {
via: "redirect",
redirectUri: "http://localhost:8000/example/index.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
},
});
为选择授权方法提供了方便的方法(第1条)popup 或者说 redirect)基于CSS媒体查询(屏幕大小).
- {[媒体查询:字符串]:{通过:'poup' }`rediction', 授权参数}}
弹出
授权
const response = await criiptoAuth.popup.authorize({
width: 300,
height: 400,
redirectUri: "http://localhost:8000/example/popup-callback.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
/** Using a random state is helpful,
* if your users are able to
* trigger new popups while a request
* is still pending */
state: Math.random().toString(),
});
console.log(response.id_token, response.claims);
- 宽度( 可选的, 数字):弹出处的宽.
- 高度( 可选的, 数字): 弹出高度
- 授权参数
自动方向
授权
criiptoAuth.redirect.authorize({
redirectUri: "http://localhost:8000/example/index.html",
acrValues: "urn:grn:authn:dk:mitid:substantial",
});
将用户浏览器标签重定向到授权 URL 。 经批准后,用户将重新定向到所提供的位置 redirectUri。 。 。 .
匹配
const match = await criiptoAuth.redirect.match();
console.log(match.code);
console.log(match.id_token, match.claims);
返回带有代码或 id token 密钥的对象(如果在其中存在) window.location 搜索(query params)或散列.
注销
如果您为您的域启用了 SSO 而您没有使用 prompt=login 您可以使用 logout() 清除用户SSO会话.
criiptoAuth.logout({
redirectUri: "http://localhost:8000/example/index.html",
});