MCPcopy
hub / github.com/pocketbase/pocketbase / BindSecurity

Function BindSecurity

plugins/jsvm/binds.go:709–750  ·  view source on GitHub ↗

BindSecurity registers $security.* namespaced object with common security related helpers. See https://pocketbase.io/jsvm/modules/_security.html.

(vm *goja.Runtime)

Source from the content-addressed store, hash-verified

707//
708// See https://pocketbase.io/jsvm/modules/_security.html.
709func BindSecurity(vm *goja.Runtime) {
710 obj := vm.NewObject()
711 vm.Set("$security", obj)
712
713 // crypto
714 obj.Set("md5", security.MD5)
715 obj.Set("sha256", security.SHA256)
716 obj.Set("sha512", security.SHA512)
717 obj.Set("hs256", security.HS256)
718 obj.Set("hs512", security.HS512)
719 obj.Set("equal", security.Equal)
720
721 // random
722 obj.Set("randomString", security.RandomString)
723 obj.Set("randomStringByRegex", security.RandomStringByRegex)
724 obj.Set("randomStringWithAlphabet", security.RandomStringWithAlphabet)
725 obj.Set("pseudorandomString", security.PseudorandomString)
726 obj.Set("pseudorandomStringWithAlphabet", security.PseudorandomStringWithAlphabet)
727
728 // jwt
729 obj.Set("parseUnverifiedJWT", func(token string) (map[string]any, error) {
730 return security.ParseUnverifiedJWT(token)
731 })
732 obj.Set("parseJWT", func(token string, verificationKey string) (map[string]any, error) {
733 return security.ParseJWT(token, verificationKey)
734 })
735 obj.Set("createJWT", func(payload jwt.MapClaims, signingKey string, secDuration int) (string, error) {
736 return security.NewJWT(payload, signingKey, time.Duration(secDuration)*time.Second)
737 })
738
739 // encryption
740 obj.Set("encrypt", security.Encrypt)
741 obj.Set("decrypt", func(cipherText, key string) (string, error) {
742 result, err := security.Decrypt(cipherText, key)
743
744 if err != nil {
745 return "", err
746 }
747
748 return string(result), err
749 })
750}
751
752// BindFilesystem registers $filesystem.* namespaced object with
753// common filesystem package related helpers.

Callers 7

TestBindSecurityCountFunction · 0.85
TestSecurityCryptoBindsFunction · 0.85
TestSecurityJWTBindsFunction · 0.85
registerMigrationsMethod · 0.85
registerHooksMethod · 0.85

Calls 5

ParseUnverifiedJWTFunction · 0.92
ParseJWTFunction · 0.92
NewJWTFunction · 0.92
DecryptFunction · 0.92
SetMethod · 0.65

Tested by 5

TestBindSecurityCountFunction · 0.68
TestSecurityCryptoBindsFunction · 0.68
TestSecurityJWTBindsFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…