@typekcz-nocobase-plugins/plugin-oidc-plus 1.0.0-1 → 1.0.0-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/OIDCButton.d.ts +9 -0
- package/dist/client/Options.d.ts +2 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.js +18 -0
- package/dist/client/locale/index.d.ts +3 -0
- package/dist/constants.d.ts +4 -0
- package/dist/constants.js +46 -0
- package/dist/externalVersion.js +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +40 -0
- package/dist/locale/es-ES.json +25 -0
- package/dist/locale/fr-FR.json +21 -0
- package/dist/locale/ko_KR.json +28 -0
- package/dist/locale/pt-BR.json +21 -0
- package/dist/locale/zh-CN.json +28 -0
- package/dist/node_modules/nanoid/LICENSE +20 -0
- package/dist/node_modules/nanoid/async/index.browser.cjs +34 -0
- package/dist/node_modules/nanoid/async/index.browser.js +34 -0
- package/dist/node_modules/nanoid/async/index.cjs +35 -0
- package/dist/node_modules/nanoid/async/index.d.ts +56 -0
- package/dist/node_modules/nanoid/async/index.js +35 -0
- package/dist/node_modules/nanoid/async/index.native.js +26 -0
- package/dist/node_modules/nanoid/async/package.json +12 -0
- package/dist/node_modules/nanoid/bin/nanoid.cjs +55 -0
- package/dist/node_modules/nanoid/index.browser.cjs +34 -0
- package/dist/node_modules/nanoid/index.browser.js +34 -0
- package/dist/node_modules/nanoid/index.cjs +1 -0
- package/dist/node_modules/nanoid/index.d.ts +91 -0
- package/dist/node_modules/nanoid/index.js +45 -0
- package/dist/node_modules/nanoid/nanoid.js +1 -0
- package/dist/node_modules/nanoid/non-secure/index.cjs +21 -0
- package/dist/node_modules/nanoid/non-secure/index.d.ts +33 -0
- package/dist/node_modules/nanoid/non-secure/index.js +21 -0
- package/dist/node_modules/nanoid/non-secure/package.json +6 -0
- package/dist/node_modules/nanoid/package.json +1 -0
- package/dist/node_modules/nanoid/url-alphabet/index.cjs +3 -0
- package/dist/node_modules/nanoid/url-alphabet/index.js +3 -0
- package/dist/node_modules/nanoid/url-alphabet/package.json +6 -0
- package/dist/node_modules/openid-client/lib/client.js +1849 -0
- package/dist/node_modules/openid-client/lib/device_flow_handle.js +125 -0
- package/dist/node_modules/openid-client/lib/errors.js +55 -0
- package/dist/node_modules/openid-client/lib/helpers/assert.js +24 -0
- package/dist/node_modules/openid-client/lib/helpers/base64url.js +13 -0
- package/dist/node_modules/openid-client/lib/helpers/client.js +211 -0
- package/dist/node_modules/openid-client/lib/helpers/consts.js +7 -0
- package/dist/node_modules/openid-client/lib/helpers/decode_jwt.js +27 -0
- package/dist/node_modules/openid-client/lib/helpers/deep_clone.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/defaults.js +27 -0
- package/dist/node_modules/openid-client/lib/helpers/generators.js +14 -0
- package/dist/node_modules/openid-client/lib/helpers/is_key_object.js +4 -0
- package/dist/node_modules/openid-client/lib/helpers/is_plain_object.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/issuer.js +111 -0
- package/dist/node_modules/openid-client/lib/helpers/keystore.js +298 -0
- package/dist/node_modules/openid-client/lib/helpers/merge.js +24 -0
- package/dist/node_modules/openid-client/lib/helpers/pick.js +9 -0
- package/dist/node_modules/openid-client/lib/helpers/process_response.js +71 -0
- package/dist/node_modules/openid-client/lib/helpers/request.js +200 -0
- package/dist/node_modules/openid-client/lib/helpers/unix_timestamp.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/weak_cache.js +1 -0
- package/dist/node_modules/openid-client/lib/helpers/webfinger_normalize.js +71 -0
- package/dist/node_modules/openid-client/lib/helpers/www_authenticate_parser.js +14 -0
- package/dist/node_modules/openid-client/lib/index.js +1 -0
- package/dist/node_modules/openid-client/lib/issuer.js +191 -0
- package/dist/node_modules/openid-client/lib/issuer_registry.js +3 -0
- package/dist/node_modules/openid-client/lib/passport_strategy.js +205 -0
- package/dist/node_modules/openid-client/lib/token_set.js +35 -0
- package/dist/node_modules/openid-client/package.json +1 -0
- package/dist/node_modules/openid-client/types/index.d.ts +622 -0
- package/dist/server/actions/getAuthUrl.d.ts +2 -0
- package/dist/server/actions/getAuthUrl.js +56 -0
- package/dist/server/actions/redirect.d.ts +2 -0
- package/dist/server/actions/redirect.js +64 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +42 -0
- package/dist/server/oidc-auth.d.ts +15 -0
- package/dist/server/oidc-auth.js +187 -0
- package/dist/server/plugin.d.ts +11 -0
- package/dist/server/plugin.js +93 -0
- package/dist/swagger/index.d.ts +143 -0
- package/dist/swagger/index.js +187 -0
- package/package.json +2 -2
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Authenticator } from '@nocobase/plugin-auth/client';
|
|
3
|
+
export interface OIDCProvider {
|
|
4
|
+
clientId: string;
|
|
5
|
+
title: string;
|
|
6
|
+
}
|
|
7
|
+
export declare const OIDCButton: ({ authenticator }: {
|
|
8
|
+
authenticator: Authenticator;
|
|
9
|
+
}) => React.JSX.Element;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
(function(o,i){typeof exports=="object"&&typeof module!="undefined"?i(exports,require("@nocobase/client"),require("@nocobase/plugin-auth/client"),require("react/jsx-runtime"),require("@ant-design/icons"),require("antd"),require("react"),require("react-i18next"),require("react-router-dom"),require("@formily/antd-v5"),require("@formily/react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","@nocobase/plugin-auth/client","react/jsx-runtime","@ant-design/icons","antd","react","react-i18next","react-router-dom","@formily/antd-v5","@formily/react"],i):(o=typeof globalThis!="undefined"?globalThis:o||self,i(o["@typekcz-nocobase-plugins/plugin-oidc-plus"]={},o["@nocobase/client"],o["@nocobase/plugin-auth"],o.jsxRuntime,o["@ant-design/icons"],o.antd,o.react,o["react-i18next"],o["react-router-dom"],o["@formily/antd-v5"],o["@formily/react"]))})(this,function(o,i,S,l,C,y,w,T,f,b,R){"use strict";var U=(o,i,S)=>new Promise((l,C)=>{var y=f=>{try{T(S.next(f))}catch(b){C(b)}},w=f=>{try{T(S.throw(f))}catch(b){C(b)}},T=f=>f.done?l(f.value):Promise.resolve(f.value).then(y,w);T((S=S.apply(o,i)).next())});const _="OIDC+",E="tnp_oidc_plus_logout",O="oidc";function s(e){return i.i18n.t(e,{ns:O})}function P(){return T.useTranslation(O)}function B(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var k={exports:{}};/*!
|
|
11
|
+
* JavaScript Cookie v2.2.1
|
|
12
|
+
* https://github.com/js-cookie/js-cookie
|
|
13
|
+
*
|
|
14
|
+
* Copyright 2006, 2015 Klaus Hartl & Fagner Brack
|
|
15
|
+
* Released under the MIT license
|
|
16
|
+
*/(function(e,h){(function(d){var x;if(e.exports=d(),x=!0,!x){var u=window.Cookies,n=window.Cookies=d();n.noConflict=function(){return window.Cookies=u,n}}})(function(){function d(){for(var n=0,c={};n<arguments.length;n++){var p=arguments[n];for(var g in p)c[g]=p[g]}return c}function x(n){return n.replace(/(%[0-9A-Z]{2})+/g,decodeURIComponent)}function u(n){function c(){}function p(t,a,r){if(typeof document!="undefined"){r=d({path:"/"},c.defaults,r),typeof r.expires=="number"&&(r.expires=new Date(new Date*1+r.expires*864e5)),r.expires=r.expires?r.expires.toUTCString():"";try{var F=JSON.stringify(a);/^[\{\[]/.test(F)&&(a=F)}catch(m){}a=n.write?n.write(a,t):encodeURIComponent(String(a)).replace(/%(23|24|26|2B|3A|3C|3E|3D|2F|3F|40|5B|5D|5E|60|7B|7D|7C)/g,decodeURIComponent),t=encodeURIComponent(String(t)).replace(/%(23|24|26|2B|5E|60|7C)/g,decodeURIComponent).replace(/[\(\)]/g,escape);var I="";for(var v in r)r[v]&&(I+="; "+v,r[v]!==!0&&(I+="="+r[v].split(";")[0]));return document.cookie=t+"="+a+I}}function g(t,a){if(typeof document!="undefined"){for(var r={},F=document.cookie?document.cookie.split("; "):[],I=0;I<F.length;I++){var v=F[I].split("="),m=v.slice(1).join("=");!a&&m.charAt(0)==='"'&&(m=m.slice(1,-1));try{var A=x(v[0]);if(m=(n.read||n)(m,A)||x(m),a)try{m=JSON.parse(m)}catch(L){}if(r[A]=m,t===A)break}catch(L){}}return t?r[t]:r}}return c.set=p,c.get=function(t){return g(t,!1)},c.getJSON=function(t){return g(t,!0)},c.remove=function(t,a){p(t,"",d(a,{expires:-1}))},c.defaults={},c.withConverter=u,c}return u(function(){})})})(k);var D=k.exports;const j=B(D),M=({authenticator:e})=>{const{t:h}=P(),d=i.useAPIClient(),x=f.useLocation(),u=new URLSearchParams(x.search),n=u.get("redirect"),c=()=>U(this,null,function*(){var t;const p=yield d.request({method:"post",url:"oidc:getAuthUrl",headers:{"X-Authenticator":e.name},data:{redirect:n}}),g=(t=p==null?void 0:p.data)==null?void 0:t.data;window.location.replace(g)});return w.useEffect(()=>{const p=j.get(E);if(p){const a=new URL(p);a.searchParams.set("post_logout_redirect_uri",window.location.href),j.remove(E),window.location.href=a.href}const g=u.get("authenticator"),t=u.get("error");if(g===e.name&&t){y.message.error(h(t));return}}),l.jsx(y.Space,{direction:"vertical",className:i.css`
|
|
17
|
+
display: flex;
|
|
18
|
+
`,children:l.jsx(y.Button,{shape:"round",block:!0,icon:l.jsx(C.LoginOutlined,{}),onClick:c,children:h(e.title)})})},N={type:"object",properties:{public:{type:"object",properties:{autoSignup:{"x-decorator":"FormItem",type:"boolean",title:'{{t("Sign up automatically when the user does not exist")}}',"x-component":"Checkbox",default:!0}}},oidc:{type:"object",properties:{collapse:{type:"void","x-component":"FormTab",properties:{basic:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:s("Basic configuration")},properties:{issuer:{type:"string",title:'{{t("Issuer")}}',"x-component":"Input","x-decorator":"FormItem",required:!0},clientId:{type:"string",title:'{{t("Client ID")}}',"x-component":"Input","x-decorator":"FormItem",required:!0},clientSecret:{type:"string",title:'{{t("Client Secret")}}',"x-component":"Input","x-decorator":"FormItem",required:!0},scope:{type:"string",title:'{{t("scope")}}',"x-component":"Input","x-decorator":"FormItem","x-decorator-props":{tooltip:'{{t("Default: openid profile email")}}'}},idTokenSignedResponseAlg:{type:"string",title:'{{t("id_token signed response algorithm")}}',"x-component":"Select","x-decorator":"FormItem",enum:[{label:"HS256",value:"HS256"},{label:"HS384",value:"HS384"},{label:"HS512",value:"HS512"},{label:"RS256",value:"RS256"},{label:"RS384",value:"RS384"},{label:"RS512",value:"RS512"},{label:"ES256",value:"ES256"},{label:"ES384",value:"ES384"},{label:"ES512",value:"ES512"},{label:"PS256",value:"PS256"},{label:"PS384",value:"PS384"},{label:"PS512",value:"PS512"}]}}},mapping:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:s("Field mapping")},properties:{fieldMap:{title:'{{t("Field Map")}}',type:"array","x-decorator":"FormItem","x-component":"ArrayItems",items:{type:"object","x-decorator":"ArrayItems.Item",properties:{space:{type:"void","x-component":"Space",properties:{source:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("source")}}'}},target:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("target")}}'}},remove:{type:"void","x-decorator":"FormItem","x-component":"ArrayItems.Remove"}}}}},properties:{add:{type:"void",title:"Add","x-component":"ArrayItems.Addition"}}},userBindField:{type:"string",title:'{{t("Use this field to bind the user")}}',"x-component":"Select","x-decorator":"FormItem",default:"email",enum:[{label:s("Email"),value:"email"},{label:s("Username"),value:"username"}],required:!0}}},advanced:{type:"void","x-component":"FormTab.TabPane","x-component-props":{tab:s("Advanced configuration")},properties:{logout:{type:"boolean",title:'{{t("RP-initiated logout")}}',"x-component":"Checkbox","x-decorator":"FormItem","x-decorator-props":{tooltip:'{{t("Performs logout on the issuer (uses end_session_endpoint in the issuer configuration)")}}'}},http:{type:"boolean",title:'{{t("HTTP")}}',"x-component":"Checkbox","x-decorator":"FormItem","x-decorator-props":{tooltip:'{{t("Check if NocoBase is running on HTTP protocol")}}'}},port:{type:"number",title:'{{t("Port")}}',"x-component":"InputNumber","x-decorator":"FormItem","x-decorator-props":{tooltip:'{{t("The port number of the NocoBase service if it is not 80 or 443")}}'},"x-component-props":{style:{width:"15%",minWidth:"100px"}}},stateToken:{type:"string",title:'{{t("State token")}}',"x-component":"Input","x-decorator":"FormItem",description:s("The state token helps prevent CSRF attacks. It's recommended to leave it blank for automatic random generation.")},exchangeBodyKeys:{type:"array",title:'{{t("Pass parameters in the authorization code grant exchange")}}',"x-decorator":"FormItem","x-component":"ArrayItems",default:[{paramName:"",optionsKey:"clientId"},{paramName:"",optionsKey:"clientSecret"}],items:{type:"object","x-decorator":"ArrayItems.Item",properties:{space:{type:"void","x-component":"Space",properties:{enabled:{type:"boolean","x-decorator":"FormItem","x-component":"Checkbox"},optionsKey:{type:"string","x-decorator":"FormItem","x-decorator-props":{style:{width:"100px"}},"x-component":"Select","x-read-pretty":!0,enum:[{label:s("Client ID"),value:"clientId"},{label:s("Client Secret"),value:"clientSecret"}]},paramName:{type:"string","x-decorator":"FormItem","x-component":"Input","x-component-props":{placeholder:'{{t("Parameter name")}}'}}}}}}},userInfoMethod:{type:"string",title:'{{t("Method to call the user info endpoint")}}',"x- decorator":"FormItem","x-component":"Radio.Group",default:"GET",enum:[{label:"GET",value:"GET"},{label:"POST",value:"POST"}],"x-reactions":[{dependencies:[".accessTokenVia"],when:'{{$deps[0] === "query"}}',fulfill:{state:{value:"GET"}}},{dependencies:[".accessTokenVia"],when:'{{$deps[0] === "body"}}',fulfill:{state:{value:"POST"}}}]},accessTokenVia:{type:"string",title:'{{t("Where to put the access token when calling the user info endpoint")}}',"x- decorator":"FormItem","x-component":"Radio.Group",default:"header",enum:[{label:s("Header"),value:"header"},{label:s("Body (Use with POST method)"),value:"body"},{label:s("Query parameters (Use with GET method)"),value:"query"}]}}}}}}},usage:{type:"void","x-component":"Usage"}}},H=R.observer(()=>{const{t:e}=P(),h=i.useApp(),d=w.useMemo(()=>h.getApiUrl("oidc:redirect"),[h]),x=u=>{navigator.clipboard.writeText(u),y.message.success(e("Copied"))};return l.jsx(y.Card,{title:e("Usage"),type:"inner",children:l.jsx(i.FormItem,{label:e("Redirect URL"),children:l.jsx(i.Input,{value:d,disabled:!0,addonBefore:l.jsx(C.CopyOutlined,{onClick:()=>x(d)})})})})},{displayName:"Usage"}),G=()=>{const{t:e}=P();return l.jsx(i.SchemaComponent,{scope:{t:e},components:{Usage:H,ArrayItems:b.ArrayItems,Space:y.Space,FormTab:b.FormTab},schema:N})};class q extends i.Plugin{load(){return U(this,null,function*(){this.app.pm.get(S).registerType(_,{components:{SignInButton:M,AdminSettingsForm:G}})})}}o.PluginOIDCClient=q,o.default=q,Object.defineProperties(o,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name2 in all)
|
|
16
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var constants_exports = {};
|
|
28
|
+
__export(constants_exports, {
|
|
29
|
+
authType: () => authType,
|
|
30
|
+
cookieName: () => cookieName,
|
|
31
|
+
logoutCookieName: () => logoutCookieName,
|
|
32
|
+
namespace: () => namespace
|
|
33
|
+
});
|
|
34
|
+
module.exports = __toCommonJS(constants_exports);
|
|
35
|
+
var import_package = require("../package.json");
|
|
36
|
+
const authType = "OIDC+";
|
|
37
|
+
const cookieName = "tnp_oidc_plus";
|
|
38
|
+
const logoutCookieName = "tnp_oidc_plus_logout";
|
|
39
|
+
const namespace = import_package.name;
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
authType,
|
|
43
|
+
cookieName,
|
|
44
|
+
logoutCookieName,
|
|
45
|
+
namespace
|
|
46
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = {
|
|
11
|
+
"@ant-design/icons": "5.2.6",
|
|
12
|
+
"@nocobase/client": "1.0.0-alpha.12",
|
|
13
|
+
"antd": "5.12.8",
|
|
14
|
+
"react": "18.2.0",
|
|
15
|
+
"react-router-dom": "6.21.0",
|
|
16
|
+
"@nocobase/plugin-auth": "1.0.0-alpha.12",
|
|
17
|
+
"@formily/antd-v5": "1.1.9",
|
|
18
|
+
"@formily/react": "2.3.0",
|
|
19
|
+
"@nocobase/auth": "1.0.0-alpha.12",
|
|
20
|
+
"@nocobase/server": "1.0.0-alpha.12",
|
|
21
|
+
"react-i18next": "11.18.6",
|
|
22
|
+
"@nocobase/actions": "1.0.0-alpha.12"
|
|
23
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is part of the NocoBase (R) project.
|
|
3
|
+
* Copyright (c) 2020-2024 NocoBase Co., Ltd.
|
|
4
|
+
* Authors: NocoBase Team.
|
|
5
|
+
*
|
|
6
|
+
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
|
7
|
+
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var __create = Object.create;
|
|
11
|
+
var __defProp = Object.defineProperty;
|
|
12
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
13
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
14
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
15
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
16
|
+
var __export = (target, all) => {
|
|
17
|
+
for (var name in all)
|
|
18
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
19
|
+
};
|
|
20
|
+
var __copyProps = (to, from, except, desc) => {
|
|
21
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
22
|
+
for (let key of __getOwnPropNames(from))
|
|
23
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
24
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
25
|
+
}
|
|
26
|
+
return to;
|
|
27
|
+
};
|
|
28
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
29
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
30
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
31
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
32
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
33
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
34
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
35
|
+
mod
|
|
36
|
+
));
|
|
37
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
38
|
+
var src_exports = {};
|
|
39
|
+
__export(src_exports, {
|
|
40
|
+
default: () => import_server.default
|
|
41
|
+
});
|
|
42
|
+
module.exports = __toCommonJS(src_exports);
|
|
43
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
44
|
+
var import_server = __toESM(require("./server"));
|
|
45
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
46
|
+
0 && (module.exports = {
|
|
47
|
+
...require("./server")
|
|
48
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "Enable",
|
|
3
|
+
"Issuer": "Issuer",
|
|
4
|
+
"OIDC manager": "OIDC manager",
|
|
5
|
+
"OIDC Providers": "OIDC Providers",
|
|
6
|
+
"Provider name": "Name",
|
|
7
|
+
"Client id": "Client id",
|
|
8
|
+
"Client secret": "Client secret",
|
|
9
|
+
"Openid configuration": "Openid configuration",
|
|
10
|
+
"Authorization endpoint": "Authorization endpoint",
|
|
11
|
+
"Access token endpoint": "Access token endpoint",
|
|
12
|
+
"JWKS endpoint": "JWKS endpoint",
|
|
13
|
+
"Userinfo endpoint": "Userinfo endpoint",
|
|
14
|
+
"Redirect url": "Redirect url",
|
|
15
|
+
"Logout endpoint": "Logout endpoint",
|
|
16
|
+
"Id token sign alg": "Id token sign alg",
|
|
17
|
+
"Add provider": "Add",
|
|
18
|
+
"Edit provider": "Edit",
|
|
19
|
+
"Delete provider": "Delete",
|
|
20
|
+
"Sign in button name, which will be displayed on the sign in page": "Sign in button name, which will be displayed on the sign in page",
|
|
21
|
+
"Use this field to bind the user": "Use this field to bind the user",
|
|
22
|
+
"Sign up automatically when the user does not exist": "Sign up automatically when the user does not exist",
|
|
23
|
+
"Username must be 2-16 characters in length (excluding @.<>\"'/)": "Username must be 2-16 characters in length (excluding @.<>\"'/)",
|
|
24
|
+
"User not found": "User not found",
|
|
25
|
+
"Basic configuration": "Basic configuration",
|
|
26
|
+
"Field mapping": "Field mapping",
|
|
27
|
+
"Advanced configuration": "Advanced configuration",
|
|
28
|
+
"Usage": "Usage",
|
|
29
|
+
"Redirect URL": "Redirect URL",
|
|
30
|
+
"Check if NocoBase is running on HTTP protocol": "Check if NocoBase is running on HTTP protocol",
|
|
31
|
+
"The port number of the NocoBase service if it is not 80 or 443": "The port number of the NocoBase service if it is not 80 or 443",
|
|
32
|
+
"Pass parameters in the authorization code grant exchange": "Pass parameters in the authorization code grant exchange",
|
|
33
|
+
"Method to call the user info endpoint": "Method to call the user info endpoint",
|
|
34
|
+
"Where to put the access token when calling the user info endpoint": "Where to put the access token when calling the user info endpoint",
|
|
35
|
+
"Header": "Header",
|
|
36
|
+
"Body (Use with POST method)": "Body (Use with POST method)",
|
|
37
|
+
"Query parameters (Use with GET method)": "Query parameters (Use with GET method)",
|
|
38
|
+
"Parameter name": "Parameter name",
|
|
39
|
+
"The state token helps prevent CSRF attacks. It's recommended to leave it blank for automatic random generation.": "The state token helps prevent CSRF attacks. It's recommended to leave it blank for automatic random generation."
|
|
40
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "Activar",
|
|
3
|
+
"Issuer": "Emisor",
|
|
4
|
+
"Actions": "Acciones",
|
|
5
|
+
"Delete": "Borrar",
|
|
6
|
+
"Edit": "Editar",
|
|
7
|
+
"Button title": "Título del botón",
|
|
8
|
+
"OIDC manager": "Gestor OIDC",
|
|
9
|
+
"OIDC Providers": "Proveedores OIDC",
|
|
10
|
+
"Provider name": "Nombre",
|
|
11
|
+
"Client id": "Id de cliente",
|
|
12
|
+
"Client secret": "Secreto del cliente",
|
|
13
|
+
"Openid configuration": "Configuración Openid",
|
|
14
|
+
"Authorization endpoint": "Endpoint de autorización ",
|
|
15
|
+
"Access token endpoint": "Endpoint de token de acceso",
|
|
16
|
+
"JWKS endpoint": "Endpoint de JWKS",
|
|
17
|
+
"Userinfo endpoint": "Userinfo endpoint",
|
|
18
|
+
"Redirect url": "Redirect url",
|
|
19
|
+
"Logout endpoint": "Endpoint de cierre de sesión",
|
|
20
|
+
"Id token sign alg": "Id token sign alg",
|
|
21
|
+
"Add provider": "Añadir Proveedor",
|
|
22
|
+
"Edit provider": "Editar Proveedor",
|
|
23
|
+
"Delete provider": "Borrar Proveedor",
|
|
24
|
+
"Sign in button name, which will be displayed on the sign in page": "Nombre del botón de inicio de sesión, que se mostrará en la página de inicio de sesión"
|
|
25
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "Activer",
|
|
3
|
+
"Issuer": "Issuer",
|
|
4
|
+
"OIDC manager": "OIDC manager",
|
|
5
|
+
"OIDC Providers": "OIDC Providers",
|
|
6
|
+
"Provider name": "Nom",
|
|
7
|
+
"Client id": "Client id",
|
|
8
|
+
"Client secret": "Client secret",
|
|
9
|
+
"Openid configuration": "Openid configuration",
|
|
10
|
+
"Authorization endpoint": "Authorization endpoint",
|
|
11
|
+
"Access token endpoint": "Access token endpoint",
|
|
12
|
+
"JWKS endpoint": "JWKS endpoint",
|
|
13
|
+
"Userinfo endpoint": "Userinfo endpoint",
|
|
14
|
+
"Redirect url": "Redirect url",
|
|
15
|
+
"Logout endpoint": "Logout endpoint",
|
|
16
|
+
"Id token sign alg": "Id token sign alg",
|
|
17
|
+
"Add provider": "Ajouter",
|
|
18
|
+
"Edit provider": "Modifier",
|
|
19
|
+
"Delete provider": "Supprimer",
|
|
20
|
+
"Sign in button name, which will be displayed on the sign in page": "Nom du bouton de connexion, qui sera affiché sur la page de connexion"
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "활성화",
|
|
3
|
+
"Actions": "작업",
|
|
4
|
+
"Delete": "삭제",
|
|
5
|
+
"Edit": "편집",
|
|
6
|
+
"Copied": "복사됨",
|
|
7
|
+
"Field Map": "필드 매핑",
|
|
8
|
+
"id_token signed response algorithm": "id_token 서명 응답 알고리즘",
|
|
9
|
+
"Use this field to bind the user": "이 필드를 사용하여 사용자를 바인딩합니다",
|
|
10
|
+
"Sign up automatically when the user does not exist": "사용자가 존재하지 않을 때 자동으로 가입",
|
|
11
|
+
"Username must be 2-16 characters in length (excluding @.<>\"'/)": "사용자 이름은 2-16 자여야합니다 (@.<>\"'/ 제외)",
|
|
12
|
+
"User not found": "사용자를 찾을 수 없음",
|
|
13
|
+
"Basic configuration": "기본 설정",
|
|
14
|
+
"Field mapping": "필드 매핑",
|
|
15
|
+
"Advanced configuration": "고급 설정",
|
|
16
|
+
"Usage": "사용 방법",
|
|
17
|
+
"Redirect URL": "리디렉션 URL",
|
|
18
|
+
"Check if NocoBase is running on HTTP protocol": "NocoBase가 HTTP 프로토콜에서 실행 중인지 확인",
|
|
19
|
+
"The port number of the NocoBase service if it is not 80 or 443": "NocoBase 서비스의 포트 번호, 기본값은 443/80",
|
|
20
|
+
"Pass parameters in the authorization code grant exchange": "권한 부여 코드 교환 중에 매개 변수를 전달",
|
|
21
|
+
"Method to call the user info endpoint": "사용자 정보 엔드포인트를 호출하는 방법",
|
|
22
|
+
"Where to put the access token when calling the user info endpoint": "사용자 정보 엔드포인트를 호출할 때 access_token을 어디에 두어야 하는지",
|
|
23
|
+
"Header": "헤더 (기본값)",
|
|
24
|
+
"Body (Use with POST method)": "바디 (POST 방식과 함께 사용)",
|
|
25
|
+
"Query parameters (Use with GET method)": "쿼리 매개 변수 (GET 방식과 함께 사용)",
|
|
26
|
+
"Parameter name": "매개 변수 이름",
|
|
27
|
+
"The state token helps prevent CSRF attacks. It's recommended to leave it blank for automatic random generation.": "상태 토큰은 CSRF 공격을 방지하는 데 도움이 됩니다. 자동으로 무작위로 생성하려면 비워 두는 것이 좋습니다."
|
|
28
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "Habilitar",
|
|
3
|
+
"Issuer": "Emissor",
|
|
4
|
+
"OIDC manager": "Gerenciador OIDC",
|
|
5
|
+
"OIDC Providers": "Provedores OIDC",
|
|
6
|
+
"Provider name": "Nome do provedor",
|
|
7
|
+
"Client id": "ID do cliente",
|
|
8
|
+
"Client secret": "Segredo do cliente",
|
|
9
|
+
"Openid configuration": "Configuração OpenID",
|
|
10
|
+
"Authorization endpoint": "Endpoint de autorização",
|
|
11
|
+
"Access token endpoint": "Endpoint de token de acesso",
|
|
12
|
+
"JWKS endpoint": "Endpoint JWKS",
|
|
13
|
+
"Userinfo endpoint": "Endpoint de informações do usuário",
|
|
14
|
+
"Redirect url": "URL de redirecionamento",
|
|
15
|
+
"Logout endpoint": "Endpoint de logout",
|
|
16
|
+
"Id token sign alg": "Algoritmo de assinatura do token de ID",
|
|
17
|
+
"Add provider": "Adicionar",
|
|
18
|
+
"Edit provider": "Editar",
|
|
19
|
+
"Delete provider": "Excluir",
|
|
20
|
+
"Sign in button name, which will be displayed on the sign in page": "Nome do botão de login, que será exibido na página de login"
|
|
21
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Enable": "启用",
|
|
3
|
+
"Actions": "操作",
|
|
4
|
+
"Delete": "删除",
|
|
5
|
+
"Edit": "编辑",
|
|
6
|
+
"Copied": "已复制",
|
|
7
|
+
"Field Map": "字段映射",
|
|
8
|
+
"id_token signed response algorithm": "id_token签名算法",
|
|
9
|
+
"Use this field to bind the user": "使用此字段绑定用户",
|
|
10
|
+
"Sign up automatically when the user does not exist": "用户不存在时自动注册",
|
|
11
|
+
"Username must be 2-16 characters in length (excluding @.<>\"'/)": "用户名必须为2-16个字符并且不包含@.<>\"'/)",
|
|
12
|
+
"User not found": "用户不存在",
|
|
13
|
+
"Basic configuration": "基础配置",
|
|
14
|
+
"Field mapping": "字段映射",
|
|
15
|
+
"Advanced configuration": "高级配置",
|
|
16
|
+
"Usage": "使用",
|
|
17
|
+
"Redirect URL": "回调 URL",
|
|
18
|
+
"Check if NocoBase is running on HTTP protocol": "NocoBase 应用为HTTP协议时勾选",
|
|
19
|
+
"The port number of the NocoBase service if it is not 80 or 443": "NocoBase 应用端口,默认 443/80",
|
|
20
|
+
"Pass parameters in the authorization code grant exchange": "使用 code 交换 token 时需要传递的参数",
|
|
21
|
+
"Method to call the user info endpoint": "访问获取用户信息的 API 的 HTTP 方法",
|
|
22
|
+
"Where to put the access token when calling the user info endpoint": "访问获取用户信息的 API 时 access_token 的传递方式",
|
|
23
|
+
"Header": "请求头 (Header, 默认)",
|
|
24
|
+
"Body (Use with POST method)": "请求体(Body, 配合 POST 方法使用)",
|
|
25
|
+
"Query parameters (Use with GET method)": "请求 URL 参数(Query, 配合 GET 方法使用)",
|
|
26
|
+
"Parameter name": "参数名",
|
|
27
|
+
"The state token helps prevent CSRF attacks. It's recommended to leave it blank for automatic random generation.": "state token 用于防止 CSRF 攻击,建议留空使用自动生成的随机值。"
|
|
28
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright 2017 Andrey Sitnik <andrey@sitnik.ru>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
2
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
3
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
4
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
5
|
+
return async (size = defaultSize) => {
|
|
6
|
+
let id = ''
|
|
7
|
+
while (true) {
|
|
8
|
+
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
|
9
|
+
let i = step
|
|
10
|
+
while (i--) {
|
|
11
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
12
|
+
if (id.length === size) return id
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let nanoid = async (size = 21) => {
|
|
18
|
+
let id = ''
|
|
19
|
+
let bytes = crypto.getRandomValues(new Uint8Array(size))
|
|
20
|
+
while (size--) {
|
|
21
|
+
let byte = bytes[size] & 63
|
|
22
|
+
if (byte < 36) {
|
|
23
|
+
id += byte.toString(36)
|
|
24
|
+
} else if (byte < 62) {
|
|
25
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
26
|
+
} else if (byte < 63) {
|
|
27
|
+
id += '_'
|
|
28
|
+
} else {
|
|
29
|
+
id += '-'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return id
|
|
33
|
+
}
|
|
34
|
+
module.exports = { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
let random = async bytes => crypto.getRandomValues(new Uint8Array(bytes))
|
|
2
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
3
|
+
let mask = (2 << (Math.log(alphabet.length - 1) / Math.LN2)) - 1
|
|
4
|
+
let step = -~((1.6 * mask * defaultSize) / alphabet.length)
|
|
5
|
+
return async (size = defaultSize) => {
|
|
6
|
+
let id = ''
|
|
7
|
+
while (true) {
|
|
8
|
+
let bytes = crypto.getRandomValues(new Uint8Array(step))
|
|
9
|
+
let i = step
|
|
10
|
+
while (i--) {
|
|
11
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
12
|
+
if (id.length === size) return id
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
let nanoid = async (size = 21) => {
|
|
18
|
+
let id = ''
|
|
19
|
+
let bytes = crypto.getRandomValues(new Uint8Array(size))
|
|
20
|
+
while (size--) {
|
|
21
|
+
let byte = bytes[size] & 63
|
|
22
|
+
if (byte < 36) {
|
|
23
|
+
id += byte.toString(36)
|
|
24
|
+
} else if (byte < 62) {
|
|
25
|
+
id += (byte - 26).toString(36).toUpperCase()
|
|
26
|
+
} else if (byte < 63) {
|
|
27
|
+
id += '_'
|
|
28
|
+
} else {
|
|
29
|
+
id += '-'
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return id
|
|
33
|
+
}
|
|
34
|
+
export { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
let crypto = require('crypto')
|
|
2
|
+
let { urlAlphabet } = require('../url-alphabet/index.cjs')
|
|
3
|
+
let random = bytes =>
|
|
4
|
+
new Promise((resolve, reject) => {
|
|
5
|
+
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
|
6
|
+
if (err) {
|
|
7
|
+
reject(err)
|
|
8
|
+
} else {
|
|
9
|
+
resolve(buf)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
14
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
15
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
16
|
+
let tick = (id, size = defaultSize) =>
|
|
17
|
+
random(step).then(bytes => {
|
|
18
|
+
let i = step
|
|
19
|
+
while (i--) {
|
|
20
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
21
|
+
if (id.length === size) return id
|
|
22
|
+
}
|
|
23
|
+
return tick(id, size)
|
|
24
|
+
})
|
|
25
|
+
return size => tick('', size)
|
|
26
|
+
}
|
|
27
|
+
let nanoid = (size = 21) =>
|
|
28
|
+
random(size).then(bytes => {
|
|
29
|
+
let id = ''
|
|
30
|
+
while (size--) {
|
|
31
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
32
|
+
}
|
|
33
|
+
return id
|
|
34
|
+
})
|
|
35
|
+
module.exports = { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate secure URL-friendly unique ID. The non-blocking version.
|
|
3
|
+
*
|
|
4
|
+
* By default, the ID will have 21 symbols to have a collision probability
|
|
5
|
+
* similar to UUID v4.
|
|
6
|
+
*
|
|
7
|
+
* ```js
|
|
8
|
+
* import { nanoid } from 'nanoid/async'
|
|
9
|
+
* nanoid().then(id => {
|
|
10
|
+
* model.id = id
|
|
11
|
+
* })
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* @param size Size of the ID. The default size is 21.
|
|
15
|
+
* @returns A promise with a random string.
|
|
16
|
+
*/
|
|
17
|
+
export function nanoid(size?: number): Promise<string>
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* A low-level function.
|
|
21
|
+
* Generate secure unique ID with custom alphabet. The non-blocking version.
|
|
22
|
+
*
|
|
23
|
+
* Alphabet must contain 256 symbols or less. Otherwise, the generator
|
|
24
|
+
* will not be secure.
|
|
25
|
+
*
|
|
26
|
+
* @param alphabet Alphabet used to generate the ID.
|
|
27
|
+
* @param defaultSize Size of the ID. The default size is 21.
|
|
28
|
+
* @returns A function that returns a promise with a random string.
|
|
29
|
+
*
|
|
30
|
+
* ```js
|
|
31
|
+
* import { customAlphabet } from 'nanoid/async'
|
|
32
|
+
* const nanoid = customAlphabet('0123456789абвгдеё', 5)
|
|
33
|
+
* nanoid().then(id => {
|
|
34
|
+
* model.id = id //=> "8ё56а"
|
|
35
|
+
* })
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function customAlphabet(
|
|
39
|
+
alphabet: string,
|
|
40
|
+
defaultSize?: number
|
|
41
|
+
): (size?: number) => Promise<string>
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Generate an array of random bytes collected from hardware noise.
|
|
45
|
+
*
|
|
46
|
+
* ```js
|
|
47
|
+
* import { random } from 'nanoid/async'
|
|
48
|
+
* random(5).then(bytes => {
|
|
49
|
+
* bytes //=> [10, 67, 212, 67, 89]
|
|
50
|
+
* })
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @param bytes Size of the array.
|
|
54
|
+
* @returns A promise with a random bytes array.
|
|
55
|
+
*/
|
|
56
|
+
export function random(bytes: number): Promise<Uint8Array>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import crypto from 'crypto'
|
|
2
|
+
import { urlAlphabet } from '../url-alphabet/index.js'
|
|
3
|
+
let random = bytes =>
|
|
4
|
+
new Promise((resolve, reject) => {
|
|
5
|
+
crypto.randomFill(Buffer.allocUnsafe(bytes), (err, buf) => {
|
|
6
|
+
if (err) {
|
|
7
|
+
reject(err)
|
|
8
|
+
} else {
|
|
9
|
+
resolve(buf)
|
|
10
|
+
}
|
|
11
|
+
})
|
|
12
|
+
})
|
|
13
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
14
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
15
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
16
|
+
let tick = (id, size = defaultSize) =>
|
|
17
|
+
random(step).then(bytes => {
|
|
18
|
+
let i = step
|
|
19
|
+
while (i--) {
|
|
20
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
21
|
+
if (id.length === size) return id
|
|
22
|
+
}
|
|
23
|
+
return tick(id, size)
|
|
24
|
+
})
|
|
25
|
+
return size => tick('', size)
|
|
26
|
+
}
|
|
27
|
+
let nanoid = (size = 21) =>
|
|
28
|
+
random(size).then(bytes => {
|
|
29
|
+
let id = ''
|
|
30
|
+
while (size--) {
|
|
31
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
32
|
+
}
|
|
33
|
+
return id
|
|
34
|
+
})
|
|
35
|
+
export { nanoid, customAlphabet, random }
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { getRandomBytesAsync } from 'expo-random'
|
|
2
|
+
import { urlAlphabet } from '../url-alphabet/index.js'
|
|
3
|
+
let random = getRandomBytesAsync
|
|
4
|
+
let customAlphabet = (alphabet, defaultSize = 21) => {
|
|
5
|
+
let mask = (2 << (31 - Math.clz32((alphabet.length - 1) | 1))) - 1
|
|
6
|
+
let step = Math.ceil((1.6 * mask * defaultSize) / alphabet.length)
|
|
7
|
+
let tick = (id, size = defaultSize) =>
|
|
8
|
+
random(step).then(bytes => {
|
|
9
|
+
let i = step
|
|
10
|
+
while (i--) {
|
|
11
|
+
id += alphabet[bytes[i] & mask] || ''
|
|
12
|
+
if (id.length === size) return id
|
|
13
|
+
}
|
|
14
|
+
return tick(id, size)
|
|
15
|
+
})
|
|
16
|
+
return size => tick('', size)
|
|
17
|
+
}
|
|
18
|
+
let nanoid = (size = 21) =>
|
|
19
|
+
random(size).then(bytes => {
|
|
20
|
+
let id = ''
|
|
21
|
+
while (size--) {
|
|
22
|
+
id += urlAlphabet[bytes[size] & 63]
|
|
23
|
+
}
|
|
24
|
+
return id
|
|
25
|
+
})
|
|
26
|
+
export { nanoid, customAlphabet, random }
|