@multiplatform.one/keycloak 5.0.26 → 6.0.0
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/cjs/index.cjs +881 -17
- package/dist/esm/index.js +855 -8
- package/package.json +59 -55
- package/src/@types/expo_keycloak_auth.d.ts +4 -0
- package/src/Authenticated.tsx +1 -25
- package/src/Loading.tsx +0 -21
- package/src/authConfig.ts +0 -21
- package/src/betterAuth/client.ts +22 -0
- package/src/betterAuth/expoClient.ts +35 -0
- package/src/betterAuth/index.ts +2 -0
- package/src/hooks/index.ts +0 -21
- package/src/hooks/useAuthConfig.ts +0 -21
- package/src/hooks/useTokensFromQuery/index.native.ts +0 -21
- package/src/hooks/useTokensFromQuery/index.ts +1 -22
- package/src/hooks/useTokensFromState.ts +0 -22
- package/src/index.ts +1 -42
- package/src/keycloak/base.ts +3 -26
- package/src/keycloak/config.ts +7 -23
- package/src/keycloak/context.ts +0 -21
- package/src/keycloak/index.native.ts +1 -22
- package/src/keycloak/index.ts +29 -97
- package/src/keycloak/index.webext.ts +23 -25
- package/src/one.ts +60 -146
- package/src/provider/AfterAuth.tsx +10 -29
- package/src/provider/KeycloakProvider.tsx +2 -23
- package/src/provider/authProvider/index.native.tsx +116 -0
- package/src/provider/{AuthProvider → authProvider}/index.tsx +26 -57
- package/src/provider/{AuthProvider → authProvider}/index.webext.tsx +36 -86
- package/src/provider/{AuthProvider → authProvider}/shared.ts +5 -20
- package/src/provider/index.ts +1 -22
- package/src/session/index.native.ts +8 -20
- package/src/session/index.ts +46 -44
- package/src/session/index.webext.ts +7 -21
- package/src/state.ts +29 -30
- package/src/token.spec.ts +168 -0
- package/src/token.ts +146 -23
- package/src/types.ts +0 -21
- package/dist/cjs/Authenticated.cjs +0 -83
- package/dist/cjs/Authenticated.js +0 -54
- package/dist/cjs/Authenticated.js.map +0 -6
- package/dist/cjs/Authenticated.native.js +0 -73
- package/dist/cjs/Authenticated.native.js.map +0 -6
- package/dist/cjs/Loading.cjs +0 -39
- package/dist/cjs/Loading.js +0 -25
- package/dist/cjs/Loading.js.map +0 -6
- package/dist/cjs/Loading.native.js +0 -32
- package/dist/cjs/Loading.native.js.map +0 -6
- package/dist/cjs/authConfig.cjs +0 -29
- package/dist/cjs/authConfig.js +0 -23
- package/dist/cjs/authConfig.js.map +0 -6
- package/dist/cjs/authConfig.native.js +0 -28
- package/dist/cjs/authConfig.native.js.map +0 -6
- package/dist/cjs/hooks/index.cjs +0 -20
- package/dist/cjs/hooks/index.js +0 -17
- package/dist/cjs/hooks/index.js.map +0 -6
- package/dist/cjs/hooks/index.native.js +0 -24
- package/dist/cjs/hooks/index.native.js.map +0 -6
- package/dist/cjs/hooks/useAuthConfig.cjs +0 -30
- package/dist/cjs/hooks/useAuthConfig.js +0 -24
- package/dist/cjs/hooks/useAuthConfig.js.map +0 -6
- package/dist/cjs/hooks/useAuthConfig.native.js +0 -29
- package/dist/cjs/hooks/useAuthConfig.native.js.map +0 -6
- package/dist/cjs/hooks/useTokensFromQuery/index.cjs +0 -35
- package/dist/cjs/hooks/useTokensFromQuery/index.js +0 -29
- package/dist/cjs/hooks/useTokensFromQuery/index.js.map +0 -6
- package/dist/cjs/hooks/useTokensFromQuery/index.native.js +0 -28
- package/dist/cjs/hooks/useTokensFromQuery/index.native.js.map +0 -6
- package/dist/cjs/hooks/useTokensFromState.cjs +0 -31
- package/dist/cjs/hooks/useTokensFromState.js +0 -26
- package/dist/cjs/hooks/useTokensFromState.js.map +0 -6
- package/dist/cjs/hooks/useTokensFromState.native.js +0 -31
- package/dist/cjs/hooks/useTokensFromState.native.js.map +0 -6
- package/dist/cjs/index.js +0 -21
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/index.native.js +0 -32
- package/dist/cjs/index.native.js.map +0 -6
- package/dist/cjs/keycloak/base.cjs +0 -90
- package/dist/cjs/keycloak/base.js +0 -90
- package/dist/cjs/keycloak/base.js.map +0 -6
- package/dist/cjs/keycloak/base.native.js +0 -135
- package/dist/cjs/keycloak/base.native.js.map +0 -6
- package/dist/cjs/keycloak/config.cjs +0 -31
- package/dist/cjs/keycloak/config.js +0 -26
- package/dist/cjs/keycloak/config.js.map +0 -6
- package/dist/cjs/keycloak/config.native.js +0 -30
- package/dist/cjs/keycloak/config.native.js.map +0 -6
- package/dist/cjs/keycloak/context.cjs +0 -27
- package/dist/cjs/keycloak/context.js +0 -22
- package/dist/cjs/keycloak/context.js.map +0 -6
- package/dist/cjs/keycloak/context.native.js +0 -26
- package/dist/cjs/keycloak/context.native.js.map +0 -6
- package/dist/cjs/keycloak/index.cjs +0 -131
- package/dist/cjs/keycloak/index.electron.cjs +0 -54
- package/dist/cjs/keycloak/index.electron.js +0 -40
- package/dist/cjs/keycloak/index.electron.js.map +0 -6
- package/dist/cjs/keycloak/index.electron.native.js +0 -137
- package/dist/cjs/keycloak/index.electron.native.js.map +0 -6
- package/dist/cjs/keycloak/index.js +0 -100
- package/dist/cjs/keycloak/index.js.map +0 -6
- package/dist/cjs/keycloak/index.native.js +0 -100
- package/dist/cjs/keycloak/index.native.js.map +0 -6
- package/dist/cjs/keycloak/index.webext.cjs +0 -54
- package/dist/cjs/keycloak/index.webext.js +0 -40
- package/dist/cjs/keycloak/index.webext.js.map +0 -6
- package/dist/cjs/keycloak/index.webext.native.js +0 -137
- package/dist/cjs/keycloak/index.webext.native.js.map +0 -6
- package/dist/cjs/one.cjs +0 -121
- package/dist/cjs/one.js +0 -119
- package/dist/cjs/one.js.map +0 -6
- package/dist/cjs/one.native.js +0 -125
- package/dist/cjs/one.native.js.map +0 -6
- package/dist/cjs/provider/AfterAuth.cjs +0 -57
- package/dist/cjs/provider/AfterAuth.js +0 -44
- package/dist/cjs/provider/AfterAuth.js.map +0 -6
- package/dist/cjs/provider/AfterAuth.native.js +0 -68
- package/dist/cjs/provider/AfterAuth.native.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.cjs +0 -223
- package/dist/cjs/provider/AuthProvider/index.electron.cjs +0 -223
- package/dist/cjs/provider/AuthProvider/index.electron.js +0 -244
- package/dist/cjs/provider/AuthProvider/index.electron.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.electron.native.js +0 -299
- package/dist/cjs/provider/AuthProvider/index.electron.native.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.js +0 -241
- package/dist/cjs/provider/AuthProvider/index.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.native.js +0 -198
- package/dist/cjs/provider/AuthProvider/index.native.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.webext.cjs +0 -223
- package/dist/cjs/provider/AuthProvider/index.webext.js +0 -244
- package/dist/cjs/provider/AuthProvider/index.webext.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/index.webext.native.js +0 -299
- package/dist/cjs/provider/AuthProvider/index.webext.native.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/shared.cjs +0 -36
- package/dist/cjs/provider/AuthProvider/shared.js +0 -30
- package/dist/cjs/provider/AuthProvider/shared.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/shared.native.js +0 -40
- package/dist/cjs/provider/AuthProvider/shared.native.js.map +0 -6
- package/dist/cjs/provider/KeycloakProvider.cjs +0 -60
- package/dist/cjs/provider/KeycloakProvider.js +0 -50
- package/dist/cjs/provider/KeycloakProvider.js.map +0 -6
- package/dist/cjs/provider/KeycloakProvider.native.js +0 -54
- package/dist/cjs/provider/KeycloakProvider.native.js.map +0 -6
- package/dist/cjs/provider/index.cjs +0 -20
- package/dist/cjs/provider/index.js +0 -17
- package/dist/cjs/provider/index.js.map +0 -6
- package/dist/cjs/provider/index.native.js +0 -24
- package/dist/cjs/provider/index.native.js.map +0 -6
- package/dist/cjs/session/index.cjs +0 -36
- package/dist/cjs/session/index.electron.cjs +0 -32
- package/dist/cjs/session/index.electron.js +0 -27
- package/dist/cjs/session/index.electron.js.map +0 -6
- package/dist/cjs/session/index.electron.native.js +0 -33
- package/dist/cjs/session/index.electron.native.js.map +0 -6
- package/dist/cjs/session/index.js +0 -30
- package/dist/cjs/session/index.js.map +0 -6
- package/dist/cjs/session/index.native.js +0 -33
- package/dist/cjs/session/index.native.js.map +0 -6
- package/dist/cjs/session/index.webext.cjs +0 -32
- package/dist/cjs/session/index.webext.js +0 -27
- package/dist/cjs/session/index.webext.js.map +0 -6
- package/dist/cjs/session/index.webext.native.js +0 -33
- package/dist/cjs/session/index.webext.native.js.map +0 -6
- package/dist/cjs/state.cjs +0 -37
- package/dist/cjs/state.js +0 -31
- package/dist/cjs/state.js.map +0 -6
- package/dist/cjs/state.native.js +0 -46
- package/dist/cjs/state.native.js.map +0 -6
- package/dist/cjs/token.cjs +0 -36
- package/dist/cjs/token.js +0 -30
- package/dist/cjs/token.js.map +0 -6
- package/dist/cjs/token.native.js +0 -36
- package/dist/cjs/token.native.js.map +0 -6
- package/dist/cjs/types.cjs +0 -16
- package/dist/cjs/types.js +0 -14
- package/dist/cjs/types.js.map +0 -6
- package/dist/cjs/types.native.js +0 -15
- package/dist/cjs/types.native.js.map +0 -6
- package/dist/esm/Authenticated.js +0 -36
- package/dist/esm/Authenticated.js.map +0 -6
- package/dist/esm/Authenticated.mjs +0 -48
- package/dist/esm/Authenticated.mjs.map +0 -1
- package/dist/esm/Authenticated.native.js +0 -49
- package/dist/esm/Authenticated.native.js.map +0 -6
- package/dist/esm/Loading.js +0 -11
- package/dist/esm/Loading.js.map +0 -6
- package/dist/esm/Loading.mjs +0 -16
- package/dist/esm/Loading.mjs.map +0 -1
- package/dist/esm/Loading.native.js +0 -13
- package/dist/esm/Loading.native.js.map +0 -6
- package/dist/esm/authConfig.js +0 -7
- package/dist/esm/authConfig.js.map +0 -6
- package/dist/esm/authConfig.mjs +0 -5
- package/dist/esm/authConfig.mjs.map +0 -1
- package/dist/esm/authConfig.native.js +0 -7
- package/dist/esm/authConfig.native.js.map +0 -6
- package/dist/esm/hooks/index.js +0 -4
- package/dist/esm/hooks/index.js.map +0 -6
- package/dist/esm/hooks/index.mjs +0 -4
- package/dist/esm/hooks/index.mjs.map +0 -1
- package/dist/esm/hooks/index.native.js +0 -4
- package/dist/esm/hooks/index.native.js.map +0 -6
- package/dist/esm/hooks/useAuthConfig.js +0 -9
- package/dist/esm/hooks/useAuthConfig.js.map +0 -6
- package/dist/esm/hooks/useAuthConfig.mjs +0 -7
- package/dist/esm/hooks/useAuthConfig.mjs.map +0 -1
- package/dist/esm/hooks/useAuthConfig.native.js +0 -9
- package/dist/esm/hooks/useAuthConfig.native.js.map +0 -6
- package/dist/esm/hooks/useTokensFromQuery/index.js +0 -14
- package/dist/esm/hooks/useTokensFromQuery/index.js.map +0 -6
- package/dist/esm/hooks/useTokensFromQuery/index.mjs +0 -12
- package/dist/esm/hooks/useTokensFromQuery/index.mjs.map +0 -1
- package/dist/esm/hooks/useTokensFromQuery/index.native.js +0 -7
- package/dist/esm/hooks/useTokensFromQuery/index.native.js.map +0 -6
- package/dist/esm/hooks/useTokensFromState.js +0 -11
- package/dist/esm/hooks/useTokensFromState.js.map +0 -6
- package/dist/esm/hooks/useTokensFromState.mjs +0 -8
- package/dist/esm/hooks/useTokensFromState.mjs.map +0 -1
- package/dist/esm/hooks/useTokensFromState.native.js +0 -11
- package/dist/esm/hooks/useTokensFromState.native.js.map +0 -6
- package/dist/esm/index.js.map +0 -6
- package/dist/esm/index.mjs +0 -8
- package/dist/esm/index.mjs.map +0 -1
- package/dist/esm/index.native.js +0 -8
- package/dist/esm/index.native.js.map +0 -6
- package/dist/esm/keycloak/base.js +0 -77
- package/dist/esm/keycloak/base.js.map +0 -6
- package/dist/esm/keycloak/base.mjs +0 -66
- package/dist/esm/keycloak/base.mjs.map +0 -1
- package/dist/esm/keycloak/base.native.js +0 -116
- package/dist/esm/keycloak/base.native.js.map +0 -6
- package/dist/esm/keycloak/config.js +0 -10
- package/dist/esm/keycloak/config.js.map +0 -6
- package/dist/esm/keycloak/config.mjs +0 -8
- package/dist/esm/keycloak/config.mjs.map +0 -1
- package/dist/esm/keycloak/config.native.js +0 -10
- package/dist/esm/keycloak/config.native.js.map +0 -6
- package/dist/esm/keycloak/context.js +0 -6
- package/dist/esm/keycloak/context.js.map +0 -6
- package/dist/esm/keycloak/context.mjs +0 -4
- package/dist/esm/keycloak/context.mjs.map +0 -1
- package/dist/esm/keycloak/context.native.js +0 -6
- package/dist/esm/keycloak/context.native.js.map +0 -6
- package/dist/esm/keycloak/index.electron.js +0 -30
- package/dist/esm/keycloak/index.electron.js.map +0 -6
- package/dist/esm/keycloak/index.electron.mjs +0 -29
- package/dist/esm/keycloak/index.electron.mjs.map +0 -1
- package/dist/esm/keycloak/index.electron.native.js +0 -117
- package/dist/esm/keycloak/index.electron.native.js.map +0 -6
- package/dist/esm/keycloak/index.js +0 -98
- package/dist/esm/keycloak/index.js.map +0 -6
- package/dist/esm/keycloak/index.mjs +0 -105
- package/dist/esm/keycloak/index.mjs.map +0 -1
- package/dist/esm/keycloak/index.native.js +0 -81
- package/dist/esm/keycloak/index.native.js.map +0 -6
- package/dist/esm/keycloak/index.webext.js +0 -30
- package/dist/esm/keycloak/index.webext.js.map +0 -6
- package/dist/esm/keycloak/index.webext.mjs +0 -29
- package/dist/esm/keycloak/index.webext.mjs.map +0 -1
- package/dist/esm/keycloak/index.webext.native.js +0 -117
- package/dist/esm/keycloak/index.webext.native.js.map +0 -6
- package/dist/esm/one.js +0 -96
- package/dist/esm/one.js.map +0 -6
- package/dist/esm/one.mjs +0 -87
- package/dist/esm/one.mjs.map +0 -1
- package/dist/esm/one.native.js +0 -98
- package/dist/esm/one.native.js.map +0 -6
- package/dist/esm/provider/AfterAuth.js +0 -34
- package/dist/esm/provider/AfterAuth.js.map +0 -6
- package/dist/esm/provider/AfterAuth.mjs +0 -34
- package/dist/esm/provider/AfterAuth.mjs.map +0 -1
- package/dist/esm/provider/AfterAuth.native.js +0 -53
- package/dist/esm/provider/AfterAuth.native.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.electron.js +0 -231
- package/dist/esm/provider/AuthProvider/index.electron.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.electron.mjs +0 -189
- package/dist/esm/provider/AuthProvider/index.electron.mjs.map +0 -1
- package/dist/esm/provider/AuthProvider/index.electron.native.js +0 -281
- package/dist/esm/provider/AuthProvider/index.electron.native.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.js +0 -229
- package/dist/esm/provider/AuthProvider/index.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.mjs +0 -189
- package/dist/esm/provider/AuthProvider/index.mjs.map +0 -1
- package/dist/esm/provider/AuthProvider/index.native.js +0 -186
- package/dist/esm/provider/AuthProvider/index.native.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.webext.js +0 -231
- package/dist/esm/provider/AuthProvider/index.webext.js.map +0 -6
- package/dist/esm/provider/AuthProvider/index.webext.mjs +0 -189
- package/dist/esm/provider/AuthProvider/index.webext.mjs.map +0 -1
- package/dist/esm/provider/AuthProvider/index.webext.native.js +0 -281
- package/dist/esm/provider/AuthProvider/index.webext.native.js.map +0 -6
- package/dist/esm/provider/AuthProvider/shared.js +0 -14
- package/dist/esm/provider/AuthProvider/shared.js.map +0 -6
- package/dist/esm/provider/AuthProvider/shared.mjs +0 -11
- package/dist/esm/provider/AuthProvider/shared.mjs.map +0 -1
- package/dist/esm/provider/AuthProvider/shared.native.js +0 -17
- package/dist/esm/provider/AuthProvider/shared.native.js.map +0 -6
- package/dist/esm/provider/KeycloakProvider.js +0 -37
- package/dist/esm/provider/KeycloakProvider.js.map +0 -6
- package/dist/esm/provider/KeycloakProvider.mjs +0 -37
- package/dist/esm/provider/KeycloakProvider.mjs.map +0 -1
- package/dist/esm/provider/KeycloakProvider.native.js +0 -36
- package/dist/esm/provider/KeycloakProvider.native.js.map +0 -6
- package/dist/esm/provider/index.js +0 -4
- package/dist/esm/provider/index.js.map +0 -6
- package/dist/esm/provider/index.mjs +0 -4
- package/dist/esm/provider/index.mjs.map +0 -1
- package/dist/esm/provider/index.native.js +0 -4
- package/dist/esm/provider/index.native.js.map +0 -6
- package/dist/esm/session/index.electron.js +0 -11
- package/dist/esm/session/index.electron.js.map +0 -6
- package/dist/esm/session/index.electron.mjs +0 -8
- package/dist/esm/session/index.electron.mjs.map +0 -1
- package/dist/esm/session/index.electron.native.js +0 -11
- package/dist/esm/session/index.electron.native.js.map +0 -6
- package/dist/esm/session/index.js +0 -15
- package/dist/esm/session/index.js.map +0 -6
- package/dist/esm/session/index.mjs +0 -13
- package/dist/esm/session/index.mjs.map +0 -1
- package/dist/esm/session/index.native.js +0 -11
- package/dist/esm/session/index.native.js.map +0 -6
- package/dist/esm/session/index.webext.js +0 -11
- package/dist/esm/session/index.webext.js.map +0 -6
- package/dist/esm/session/index.webext.mjs +0 -8
- package/dist/esm/session/index.webext.mjs.map +0 -1
- package/dist/esm/session/index.webext.native.js +0 -11
- package/dist/esm/session/index.webext.native.js.map +0 -6
- package/dist/esm/state.js +0 -16
- package/dist/esm/state.js.map +0 -6
- package/dist/esm/state.mjs +0 -13
- package/dist/esm/state.mjs.map +0 -1
- package/dist/esm/state.native.js +0 -25
- package/dist/esm/state.native.js.map +0 -6
- package/dist/esm/token.js +0 -14
- package/dist/esm/token.js.map +0 -6
- package/dist/esm/token.mjs +0 -12
- package/dist/esm/token.mjs.map +0 -1
- package/dist/esm/token.native.js +0 -14
- package/dist/esm/token.native.js.map +0 -6
- package/dist/esm/types.js +0 -1
- package/dist/esm/types.js.map +0 -6
- package/dist/esm/types.mjs +0 -2
- package/dist/esm/types.mjs.map +0 -1
- package/dist/esm/types.native.js +0 -1
- package/dist/esm/types.native.js.map +0 -6
- package/dist/jsx/Authenticated.js +0 -36
- package/dist/jsx/Authenticated.js.map +0 -6
- package/dist/jsx/Authenticated.mjs +0 -48
- package/dist/jsx/Authenticated.mjs.map +0 -1
- package/dist/jsx/Authenticated.native.js +0 -49
- package/dist/jsx/Authenticated.native.js.map +0 -6
- package/dist/jsx/Loading.js +0 -11
- package/dist/jsx/Loading.js.map +0 -6
- package/dist/jsx/Loading.mjs +0 -16
- package/dist/jsx/Loading.mjs.map +0 -1
- package/dist/jsx/Loading.native.js +0 -13
- package/dist/jsx/Loading.native.js.map +0 -6
- package/dist/jsx/authConfig.js +0 -7
- package/dist/jsx/authConfig.js.map +0 -6
- package/dist/jsx/authConfig.mjs +0 -5
- package/dist/jsx/authConfig.mjs.map +0 -1
- package/dist/jsx/authConfig.native.js +0 -7
- package/dist/jsx/authConfig.native.js.map +0 -6
- package/dist/jsx/hooks/index.js +0 -4
- package/dist/jsx/hooks/index.js.map +0 -6
- package/dist/jsx/hooks/index.mjs +0 -4
- package/dist/jsx/hooks/index.mjs.map +0 -1
- package/dist/jsx/hooks/index.native.js +0 -4
- package/dist/jsx/hooks/index.native.js.map +0 -6
- package/dist/jsx/hooks/useAuthConfig.js +0 -9
- package/dist/jsx/hooks/useAuthConfig.js.map +0 -6
- package/dist/jsx/hooks/useAuthConfig.mjs +0 -7
- package/dist/jsx/hooks/useAuthConfig.mjs.map +0 -1
- package/dist/jsx/hooks/useAuthConfig.native.js +0 -9
- package/dist/jsx/hooks/useAuthConfig.native.js.map +0 -6
- package/dist/jsx/hooks/useTokensFromQuery/index.js +0 -14
- package/dist/jsx/hooks/useTokensFromQuery/index.js.map +0 -6
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs +0 -12
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs.map +0 -1
- package/dist/jsx/hooks/useTokensFromQuery/index.native.js +0 -7
- package/dist/jsx/hooks/useTokensFromQuery/index.native.js.map +0 -6
- package/dist/jsx/hooks/useTokensFromState.js +0 -11
- package/dist/jsx/hooks/useTokensFromState.js.map +0 -6
- package/dist/jsx/hooks/useTokensFromState.mjs +0 -8
- package/dist/jsx/hooks/useTokensFromState.mjs.map +0 -1
- package/dist/jsx/hooks/useTokensFromState.native.js +0 -11
- package/dist/jsx/hooks/useTokensFromState.native.js.map +0 -6
- package/dist/jsx/index.js +0 -8
- package/dist/jsx/index.js.map +0 -6
- package/dist/jsx/index.mjs +0 -8
- package/dist/jsx/index.mjs.map +0 -1
- package/dist/jsx/index.native.js +0 -8
- package/dist/jsx/index.native.js.map +0 -6
- package/dist/jsx/keycloak/base.js +0 -77
- package/dist/jsx/keycloak/base.js.map +0 -6
- package/dist/jsx/keycloak/base.mjs +0 -66
- package/dist/jsx/keycloak/base.mjs.map +0 -1
- package/dist/jsx/keycloak/base.native.js +0 -116
- package/dist/jsx/keycloak/base.native.js.map +0 -6
- package/dist/jsx/keycloak/config.js +0 -10
- package/dist/jsx/keycloak/config.js.map +0 -6
- package/dist/jsx/keycloak/config.mjs +0 -8
- package/dist/jsx/keycloak/config.mjs.map +0 -1
- package/dist/jsx/keycloak/config.native.js +0 -10
- package/dist/jsx/keycloak/config.native.js.map +0 -6
- package/dist/jsx/keycloak/context.js +0 -6
- package/dist/jsx/keycloak/context.js.map +0 -6
- package/dist/jsx/keycloak/context.mjs +0 -4
- package/dist/jsx/keycloak/context.mjs.map +0 -1
- package/dist/jsx/keycloak/context.native.js +0 -6
- package/dist/jsx/keycloak/context.native.js.map +0 -6
- package/dist/jsx/keycloak/index.electron.js +0 -30
- package/dist/jsx/keycloak/index.electron.js.map +0 -6
- package/dist/jsx/keycloak/index.electron.mjs +0 -29
- package/dist/jsx/keycloak/index.electron.mjs.map +0 -1
- package/dist/jsx/keycloak/index.electron.native.js +0 -117
- package/dist/jsx/keycloak/index.electron.native.js.map +0 -6
- package/dist/jsx/keycloak/index.js +0 -98
- package/dist/jsx/keycloak/index.js.map +0 -6
- package/dist/jsx/keycloak/index.mjs +0 -105
- package/dist/jsx/keycloak/index.mjs.map +0 -1
- package/dist/jsx/keycloak/index.native.js +0 -81
- package/dist/jsx/keycloak/index.native.js.map +0 -6
- package/dist/jsx/keycloak/index.webext.js +0 -30
- package/dist/jsx/keycloak/index.webext.js.map +0 -6
- package/dist/jsx/keycloak/index.webext.mjs +0 -29
- package/dist/jsx/keycloak/index.webext.mjs.map +0 -1
- package/dist/jsx/keycloak/index.webext.native.js +0 -117
- package/dist/jsx/keycloak/index.webext.native.js.map +0 -6
- package/dist/jsx/one.js +0 -96
- package/dist/jsx/one.js.map +0 -6
- package/dist/jsx/one.mjs +0 -87
- package/dist/jsx/one.mjs.map +0 -1
- package/dist/jsx/one.native.js +0 -98
- package/dist/jsx/one.native.js.map +0 -6
- package/dist/jsx/provider/AfterAuth.js +0 -34
- package/dist/jsx/provider/AfterAuth.js.map +0 -6
- package/dist/jsx/provider/AfterAuth.mjs +0 -34
- package/dist/jsx/provider/AfterAuth.mjs.map +0 -1
- package/dist/jsx/provider/AfterAuth.native.js +0 -53
- package/dist/jsx/provider/AfterAuth.native.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.electron.js +0 -231
- package/dist/jsx/provider/AuthProvider/index.electron.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.electron.mjs +0 -189
- package/dist/jsx/provider/AuthProvider/index.electron.mjs.map +0 -1
- package/dist/jsx/provider/AuthProvider/index.electron.native.js +0 -281
- package/dist/jsx/provider/AuthProvider/index.electron.native.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.js +0 -229
- package/dist/jsx/provider/AuthProvider/index.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.mjs +0 -189
- package/dist/jsx/provider/AuthProvider/index.mjs.map +0 -1
- package/dist/jsx/provider/AuthProvider/index.native.js +0 -186
- package/dist/jsx/provider/AuthProvider/index.native.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.webext.js +0 -231
- package/dist/jsx/provider/AuthProvider/index.webext.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/index.webext.mjs +0 -189
- package/dist/jsx/provider/AuthProvider/index.webext.mjs.map +0 -1
- package/dist/jsx/provider/AuthProvider/index.webext.native.js +0 -281
- package/dist/jsx/provider/AuthProvider/index.webext.native.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/shared.js +0 -14
- package/dist/jsx/provider/AuthProvider/shared.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/shared.mjs +0 -11
- package/dist/jsx/provider/AuthProvider/shared.mjs.map +0 -1
- package/dist/jsx/provider/AuthProvider/shared.native.js +0 -17
- package/dist/jsx/provider/AuthProvider/shared.native.js.map +0 -6
- package/dist/jsx/provider/KeycloakProvider.js +0 -37
- package/dist/jsx/provider/KeycloakProvider.js.map +0 -6
- package/dist/jsx/provider/KeycloakProvider.mjs +0 -37
- package/dist/jsx/provider/KeycloakProvider.mjs.map +0 -1
- package/dist/jsx/provider/KeycloakProvider.native.js +0 -36
- package/dist/jsx/provider/KeycloakProvider.native.js.map +0 -6
- package/dist/jsx/provider/index.js +0 -4
- package/dist/jsx/provider/index.js.map +0 -6
- package/dist/jsx/provider/index.mjs +0 -4
- package/dist/jsx/provider/index.mjs.map +0 -1
- package/dist/jsx/provider/index.native.js +0 -4
- package/dist/jsx/provider/index.native.js.map +0 -6
- package/dist/jsx/session/index.electron.js +0 -11
- package/dist/jsx/session/index.electron.js.map +0 -6
- package/dist/jsx/session/index.electron.mjs +0 -8
- package/dist/jsx/session/index.electron.mjs.map +0 -1
- package/dist/jsx/session/index.electron.native.js +0 -11
- package/dist/jsx/session/index.electron.native.js.map +0 -6
- package/dist/jsx/session/index.js +0 -15
- package/dist/jsx/session/index.js.map +0 -6
- package/dist/jsx/session/index.mjs +0 -13
- package/dist/jsx/session/index.mjs.map +0 -1
- package/dist/jsx/session/index.native.js +0 -11
- package/dist/jsx/session/index.native.js.map +0 -6
- package/dist/jsx/session/index.webext.js +0 -11
- package/dist/jsx/session/index.webext.js.map +0 -6
- package/dist/jsx/session/index.webext.mjs +0 -8
- package/dist/jsx/session/index.webext.mjs.map +0 -1
- package/dist/jsx/session/index.webext.native.js +0 -11
- package/dist/jsx/session/index.webext.native.js.map +0 -6
- package/dist/jsx/state.js +0 -16
- package/dist/jsx/state.js.map +0 -6
- package/dist/jsx/state.mjs +0 -13
- package/dist/jsx/state.mjs.map +0 -1
- package/dist/jsx/state.native.js +0 -25
- package/dist/jsx/state.native.js.map +0 -6
- package/dist/jsx/token.js +0 -14
- package/dist/jsx/token.js.map +0 -6
- package/dist/jsx/token.mjs +0 -12
- package/dist/jsx/token.mjs.map +0 -1
- package/dist/jsx/token.native.js +0 -14
- package/dist/jsx/token.native.js.map +0 -6
- package/dist/jsx/types.js +0 -1
- package/dist/jsx/types.js.map +0 -6
- package/dist/jsx/types.mjs +0 -2
- package/dist/jsx/types.mjs.map +0 -1
- package/dist/jsx/types.native.js +0 -1
- package/dist/jsx/types.native.js.map +0 -6
- package/src/@types/expoKeycloakAuth.d.ts +0 -25
- package/src/keycloak/index.electron.ts +0 -72
- package/src/provider/AuthProvider/index.electron.tsx +0 -419
- package/src/provider/AuthProvider/index.native.tsx +0 -308
- package/src/session/index.electron.ts +0 -33
- package/types/Authenticated.d.ts +0 -29
- package/types/Authenticated.d.ts.map +0 -1
- package/types/Loading.d.ts +0 -26
- package/types/Loading.d.ts.map +0 -1
- package/types/authConfig.d.ts +0 -11
- package/types/authConfig.d.ts.map +0 -1
- package/types/hooks/index.d.ts +0 -24
- package/types/hooks/index.d.ts.map +0 -1
- package/types/hooks/useAuthConfig.d.ts +0 -2
- package/types/hooks/useAuthConfig.d.ts.map +0 -1
- package/types/hooks/useTokensFromQuery/index.d.ts +0 -2
- package/types/hooks/useTokensFromQuery/index.d.ts.map +0 -1
- package/types/hooks/useTokensFromQuery/index.native.d.ts +0 -2
- package/types/hooks/useTokensFromQuery/index.native.d.ts.map +0 -1
- package/types/hooks/useTokensFromState.d.ts +0 -2
- package/types/hooks/useTokensFromState.d.ts.map +0 -1
- package/types/index.d.ts +0 -28
- package/types/index.d.ts.map +0 -1
- package/types/keycloak/base.d.ts +0 -51
- package/types/keycloak/base.d.ts.map +0 -1
- package/types/keycloak/config.d.ts +0 -8
- package/types/keycloak/config.d.ts.map +0 -1
- package/types/keycloak/context.d.ts +0 -4
- package/types/keycloak/context.d.ts.map +0 -1
- package/types/keycloak/index.d.ts +0 -15
- package/types/keycloak/index.d.ts.map +0 -1
- package/types/keycloak/index.electron.d.ts +0 -12
- package/types/keycloak/index.electron.d.ts.map +0 -1
- package/types/keycloak/index.native.d.ts +0 -27
- package/types/keycloak/index.native.d.ts.map +0 -1
- package/types/keycloak/index.webext.d.ts +0 -12
- package/types/keycloak/index.webext.d.ts.map +0 -1
- package/types/one.d.ts +0 -27
- package/types/one.d.ts.map +0 -1
- package/types/provider/AfterAuth.d.ts +0 -26
- package/types/provider/AfterAuth.d.ts.map +0 -1
- package/types/provider/AuthProvider/index.d.ts +0 -23
- package/types/provider/AuthProvider/index.d.ts.map +0 -1
- package/types/provider/AuthProvider/index.electron.d.ts +0 -23
- package/types/provider/AuthProvider/index.electron.d.ts.map +0 -1
- package/types/provider/AuthProvider/index.native.d.ts +0 -23
- package/types/provider/AuthProvider/index.native.d.ts.map +0 -1
- package/types/provider/AuthProvider/index.webext.d.ts +0 -23
- package/types/provider/AuthProvider/index.webext.d.ts.map +0 -1
- package/types/provider/AuthProvider/shared.d.ts +0 -53
- package/types/provider/AuthProvider/shared.d.ts.map +0 -1
- package/types/provider/KeycloakProvider.d.ts +0 -30
- package/types/provider/KeycloakProvider.d.ts.map +0 -1
- package/types/provider/index.d.ts +0 -24
- package/types/provider/index.d.ts.map +0 -1
- package/types/session/index.d.ts +0 -16
- package/types/session/index.d.ts.map +0 -1
- package/types/session/index.electron.d.ts +0 -5
- package/types/session/index.electron.d.ts.map +0 -1
- package/types/session/index.native.d.ts +0 -5
- package/types/session/index.native.d.ts.map +0 -1
- package/types/session/index.webext.d.ts +0 -5
- package/types/session/index.webext.d.ts.map +0 -1
- package/types/state.d.ts +0 -9
- package/types/state.d.ts.map +0 -1
- package/types/token.d.ts +0 -16
- package/types/token.d.ts.map +0 -1
- package/types/types.d.ts +0 -19
- package/types/types.d.ts.map +0 -1
package/src/session/index.ts
CHANGED
|
@@ -1,60 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
/**
|
|
2
2
|
* File: /src/session/index.ts
|
|
3
3
|
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 19-11-2024 20:26:31
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2024
|
|
8
4
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
5
|
+
* Better Auth session hook for web.
|
|
6
|
+
* Replaces the previous next-auth/react useSession.
|
|
20
7
|
*/
|
|
21
8
|
|
|
22
|
-
import { isBrowser,
|
|
23
|
-
import
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
9
|
+
import { isBrowser, isTauri } from "@multiplatform.one/platform";
|
|
10
|
+
import { getAuthClient } from "../betterAuth/client";
|
|
11
|
+
|
|
12
|
+
export interface Session {
|
|
13
|
+
accessToken?: string;
|
|
14
|
+
err?: Error;
|
|
15
|
+
idToken?: string;
|
|
16
|
+
refreshToken?: string;
|
|
17
|
+
user?: {
|
|
18
|
+
id: string;
|
|
19
|
+
name?: string | null;
|
|
20
|
+
email?: string | null;
|
|
21
|
+
image?: string | null;
|
|
22
|
+
};
|
|
23
|
+
expires?: string;
|
|
24
|
+
}
|
|
29
25
|
|
|
30
|
-
export type
|
|
31
|
-
Omit<NextSessionContextValue<R> & { session: Session }, "data">
|
|
32
|
-
>;
|
|
26
|
+
export type SessionStatus = "loading" | "authenticated" | "unauthenticated";
|
|
33
27
|
|
|
34
|
-
|
|
35
|
-
|
|
28
|
+
export interface SessionContextValue<_R extends boolean = false> {
|
|
29
|
+
session: Session | null;
|
|
30
|
+
status: SessionStatus;
|
|
31
|
+
update?: () => void;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let useSession = <R extends boolean = false>(
|
|
35
|
+
_options?: Record<string, unknown>,
|
|
36
36
|
): SessionContextValue<R> => {
|
|
37
|
-
return {};
|
|
37
|
+
return { session: null, status: "unauthenticated" };
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
-
if (isBrowser && !
|
|
41
|
-
useSession = <R extends boolean>(
|
|
42
|
-
|
|
40
|
+
if (isBrowser && !isTauri) {
|
|
41
|
+
useSession = <R extends boolean = false>(
|
|
42
|
+
_options?: Record<string, unknown>,
|
|
43
43
|
): SessionContextValue<R> => {
|
|
44
|
-
const
|
|
44
|
+
const client = getAuthClient();
|
|
45
|
+
const { data, isPending, error: _error } = client.useSession();
|
|
46
|
+
if (isPending) {
|
|
47
|
+
return { session: null, status: "loading" };
|
|
48
|
+
}
|
|
49
|
+
if (!data?.user) {
|
|
50
|
+
return { session: null, status: "unauthenticated" };
|
|
51
|
+
}
|
|
45
52
|
return {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
session: {
|
|
54
|
+
user: data.user as Session["user"],
|
|
55
|
+
expires: data.session?.expiresAt?.toString(),
|
|
56
|
+
},
|
|
57
|
+
status: "authenticated",
|
|
58
|
+
};
|
|
50
59
|
};
|
|
51
60
|
}
|
|
52
61
|
|
|
53
|
-
export interface Session extends NextSession {
|
|
54
|
-
accessToken?: string;
|
|
55
|
-
err?: Error;
|
|
56
|
-
idToken?: string;
|
|
57
|
-
refreshToken?: string;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
62
|
export { useSession };
|
|
@@ -1,33 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
* File: /src/session/index.
|
|
1
|
+
/**
|
|
2
|
+
* File: /src/session/index.webext.ts
|
|
3
3
|
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 04-04-2024 15:50:39
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2024
|
|
8
4
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
5
|
+
* Session stub for web extensions. Uses Better Auth client internally
|
|
6
|
+
* when available; otherwise returns empty session.
|
|
20
7
|
*/
|
|
21
8
|
|
|
22
|
-
import type { UseSessionOptions } from "next-auth/react";
|
|
23
9
|
import type { SessionContextValue } from "./index";
|
|
24
10
|
|
|
25
11
|
export async function getSession() {
|
|
26
12
|
return null;
|
|
27
13
|
}
|
|
28
14
|
|
|
29
|
-
export function useSession<R extends boolean>(
|
|
30
|
-
_options?:
|
|
15
|
+
export function useSession<R extends boolean = false>(
|
|
16
|
+
_options?: Record<string, unknown>,
|
|
31
17
|
): SessionContextValue<R> {
|
|
32
|
-
return {};
|
|
18
|
+
return { session: null, status: "unauthenticated" };
|
|
33
19
|
}
|
package/src/state.ts
CHANGED
|
@@ -1,35 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 19-11-2024 20:26:31
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2024
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
1
|
+
import { createStore, useStore } from "@multiplatform.one/store";
|
|
2
|
+
import { isBrowser, isIframe, isServer, isTauri } from "@multiplatform.one/platform";
|
|
21
3
|
|
|
22
|
-
|
|
23
|
-
import { isBrowser, isElectron, isIframe, isServer } from "multiplatform.one";
|
|
4
|
+
export const persist = isIframe || isTauri || (!isBrowser && !isServer);
|
|
24
5
|
|
|
25
|
-
export
|
|
6
|
+
export interface AuthTokenState {
|
|
7
|
+
idToken: string;
|
|
8
|
+
refreshToken: string;
|
|
9
|
+
token: string;
|
|
10
|
+
}
|
|
26
11
|
|
|
27
|
-
|
|
28
|
-
idToken
|
|
29
|
-
refreshToken
|
|
30
|
-
token
|
|
12
|
+
export interface AuthState extends AuthTokenState {
|
|
13
|
+
setIdToken: (idToken: string) => void;
|
|
14
|
+
setRefreshToken: (refreshToken: string) => void;
|
|
15
|
+
setToken: (token: string) => void;
|
|
16
|
+
setTokens: (tokens: { idToken?: string; refreshToken?: string; token?: string }) => void;
|
|
31
17
|
}
|
|
32
18
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
19
|
+
const authStore = createStore<AuthTokenState>(
|
|
20
|
+
{ idToken: "", refreshToken: "", token: "" },
|
|
21
|
+
{ name: "auth", persist: persist as boolean },
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
export function useAuthStore(): AuthState {
|
|
25
|
+
const state = useStore(authStore);
|
|
26
|
+
return {
|
|
27
|
+
...state,
|
|
28
|
+
setIdToken: (idToken: string) => authStore.setState((prev) => ({ ...prev, idToken })),
|
|
29
|
+
setRefreshToken: (refreshToken: string) =>
|
|
30
|
+
authStore.setState((prev) => ({ ...prev, refreshToken })),
|
|
31
|
+
setToken: (token: string) => authStore.setState((prev) => ({ ...prev, token })),
|
|
32
|
+
setTokens: (tokens) => authStore.setState((prev) => ({ ...prev, ...tokens })),
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { describe, expect, it, vi, afterEach } from "vitest";
|
|
2
|
+
import {
|
|
3
|
+
getWalletsFromToken,
|
|
4
|
+
getWalletAddresses,
|
|
5
|
+
hasWallets,
|
|
6
|
+
getAllWalletAddresses,
|
|
7
|
+
isTokenExpired,
|
|
8
|
+
validOrRefreshableToken,
|
|
9
|
+
} from "./token";
|
|
10
|
+
|
|
11
|
+
function makeJwt(payload: Record<string, unknown>): string {
|
|
12
|
+
const header = btoa(JSON.stringify({ alg: "none", typ: "JWT" }));
|
|
13
|
+
const body = btoa(JSON.stringify(payload));
|
|
14
|
+
return `${header}.${body}.`;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const walletPayload = {
|
|
18
|
+
crypto: {
|
|
19
|
+
wallets: {
|
|
20
|
+
ethereum: { addresses: ["0xABCD", "0x1234"] },
|
|
21
|
+
solana: { addresses: ["SolAddr1"] },
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const noWalletPayload = {
|
|
28
|
+
sub: "user-123",
|
|
29
|
+
exp: Math.floor(Date.now() / 1000) + 3600,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("getWalletsFromToken", () => {
|
|
33
|
+
it("extracts wallet map from a token with crypto claim", () => {
|
|
34
|
+
const token = makeJwt(walletPayload);
|
|
35
|
+
const wallets = getWalletsFromToken(token);
|
|
36
|
+
expect(wallets.ethereum?.addresses).toEqual(["0xABCD", "0x1234"]);
|
|
37
|
+
expect(wallets.solana?.addresses).toEqual(["SolAddr1"]);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("returns empty object when no crypto claim", () => {
|
|
41
|
+
const token = makeJwt(noWalletPayload);
|
|
42
|
+
expect(getWalletsFromToken(token)).toEqual({});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("returns empty object for invalid token", () => {
|
|
46
|
+
expect(getWalletsFromToken("not.a.jwt")).toEqual({});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("returns empty object for empty string", () => {
|
|
50
|
+
expect(getWalletsFromToken("")).toEqual({});
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
describe("getWalletAddresses", () => {
|
|
55
|
+
it("extracts ethereum addresses by default", () => {
|
|
56
|
+
const token = makeJwt(walletPayload);
|
|
57
|
+
expect(getWalletAddresses(token)).toEqual(["0xABCD", "0x1234"]);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("extracts addresses for a specific wallet type", () => {
|
|
61
|
+
const token = makeJwt(walletPayload);
|
|
62
|
+
expect(getWalletAddresses(token, "solana")).toEqual(["SolAddr1"]);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("returns empty array for missing wallet type", () => {
|
|
66
|
+
const token = makeJwt(walletPayload);
|
|
67
|
+
expect(getWalletAddresses(token, "sui")).toEqual([]);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("returns empty array for token without wallets", () => {
|
|
71
|
+
const token = makeJwt(noWalletPayload);
|
|
72
|
+
expect(getWalletAddresses(token)).toEqual([]);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
describe("hasWallets", () => {
|
|
77
|
+
it("returns true when token has wallet addresses", () => {
|
|
78
|
+
const token = makeJwt(walletPayload);
|
|
79
|
+
expect(hasWallets(token)).toBe(true);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("returns false when token has no crypto claim", () => {
|
|
83
|
+
const token = makeJwt(noWalletPayload);
|
|
84
|
+
expect(hasWallets(token)).toBe(false);
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
it("returns false when wallets map has empty addresses", () => {
|
|
88
|
+
const token = makeJwt({
|
|
89
|
+
crypto: { wallets: { ethereum: { addresses: [] } } },
|
|
90
|
+
});
|
|
91
|
+
expect(hasWallets(token)).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
describe("getAllWalletAddresses", () => {
|
|
96
|
+
it("returns all addresses with their wallet types", () => {
|
|
97
|
+
const token = makeJwt(walletPayload);
|
|
98
|
+
const result = getAllWalletAddresses(token);
|
|
99
|
+
expect(result).toEqual([
|
|
100
|
+
{ walletType: "ethereum", address: "0xABCD" },
|
|
101
|
+
{ walletType: "ethereum", address: "0x1234" },
|
|
102
|
+
{ walletType: "solana", address: "SolAddr1" },
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("returns empty array for token without wallets", () => {
|
|
107
|
+
const token = makeJwt(noWalletPayload);
|
|
108
|
+
expect(getAllWalletAddresses(token)).toEqual([]);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
describe("isTokenExpired", () => {
|
|
113
|
+
it("returns false for a token expiring in the future", () => {
|
|
114
|
+
const token = makeJwt({ exp: Math.floor(Date.now() / 1000) + 3600 });
|
|
115
|
+
expect(isTokenExpired(token)).toBe(false);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("returns true for a token that expired in the past", () => {
|
|
119
|
+
const token = makeJwt({ exp: Math.floor(Date.now() / 1000) - 60 });
|
|
120
|
+
expect(isTokenExpired(token)).toBe(true);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("returns false when token has no exp claim", () => {
|
|
124
|
+
const token = makeJwt({ sub: "user" });
|
|
125
|
+
expect(isTokenExpired(token)).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
describe("validOrRefreshableToken", () => {
|
|
130
|
+
const validToken = makeJwt({ exp: Math.floor(Date.now() / 1000) + 3600 });
|
|
131
|
+
const expiredToken = makeJwt({ exp: Math.floor(Date.now() / 1000) - 60 });
|
|
132
|
+
|
|
133
|
+
it("returns undefined when token is undefined", () => {
|
|
134
|
+
expect(validOrRefreshableToken(undefined)).toBeUndefined();
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("returns false when token is falsy (empty string)", () => {
|
|
138
|
+
expect(validOrRefreshableToken("")).toBe(false);
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
it("returns false when token is false", () => {
|
|
142
|
+
expect(validOrRefreshableToken(false)).toBe(false);
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it("returns the token when it is valid and no refresh token", () => {
|
|
146
|
+
expect(validOrRefreshableToken(validToken)).toBe(validToken);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("returns false when token is expired and no refresh token", () => {
|
|
150
|
+
expect(validOrRefreshableToken(expiredToken)).toBe(false);
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("returns the token when expired but refresh token is true", () => {
|
|
154
|
+
expect(validOrRefreshableToken(expiredToken, true)).toBe(expiredToken);
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it("returns the token when expired but refresh token is valid", () => {
|
|
158
|
+
expect(validOrRefreshableToken(expiredToken, validToken)).toBe(expiredToken);
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("returns false when both token and refresh token are expired", () => {
|
|
162
|
+
expect(validOrRefreshableToken(expiredToken, expiredToken)).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("returns boolean token as-is when not a string", () => {
|
|
166
|
+
expect(validOrRefreshableToken(true)).toBe(true);
|
|
167
|
+
});
|
|
168
|
+
});
|
package/src/token.ts
CHANGED
|
@@ -1,26 +1,141 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
|
|
1
|
+
import { jwtDecode } from "jwt-decode";
|
|
2
|
+
import type { KeycloakTokenParsed } from "@multiplatform.one/keycloak-js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Wallet types supported by siwe-keycloak extension.
|
|
6
|
+
* Currently supports Ethereum wallets, with Solana and Sui planned.
|
|
7
|
+
*/
|
|
8
|
+
export type WalletType = "ethereum" | "solana" | "sui";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Structure of wallet data within a chain type.
|
|
12
|
+
* Contains an array of wallet addresses for that chain.
|
|
13
|
+
*/
|
|
14
|
+
export interface WalletTypeInfo {
|
|
15
|
+
addresses: string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Map of wallet types to their wallet info.
|
|
20
|
+
* This is the structure inside token.crypto.wallets
|
|
21
|
+
*/
|
|
22
|
+
export interface WalletsMap {
|
|
23
|
+
[walletType: string]: WalletTypeInfo;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* The crypto claim structure added to tokens by siwe-wallet-mapper.
|
|
28
|
+
* Contains wallet information from the siwe-keycloak extension.
|
|
29
|
+
*/
|
|
30
|
+
export interface CryptoClaim {
|
|
31
|
+
wallets: WalletsMap;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Extracts wallet addresses from a JWT token that includes the siwe-wallet-mapper claims.
|
|
8
36
|
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
37
|
+
* The siwe-keycloak extension adds a "crypto" claim with the following structure:
|
|
38
|
+
* ```json
|
|
39
|
+
* {
|
|
40
|
+
* "crypto": {
|
|
41
|
+
* "wallets": {
|
|
42
|
+
* "ethereum": {
|
|
43
|
+
* "addresses": ["0x1234...", "0x5678..."]
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
12
49
|
*
|
|
13
|
-
*
|
|
50
|
+
* @param token - JWT access token or ID token string
|
|
51
|
+
* @returns Object containing wallet addresses by type, or empty object if no wallets
|
|
14
52
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const wallets = getWalletsFromToken(accessToken);
|
|
56
|
+
* // { ethereum: { addresses: ['0x1234...'] } }
|
|
57
|
+
*
|
|
58
|
+
* const ethAddresses = wallets.ethereum?.addresses ?? [];
|
|
59
|
+
* // ['0x1234...']
|
|
60
|
+
* ```
|
|
20
61
|
*/
|
|
62
|
+
export function getWalletsFromToken(token: string): WalletsMap {
|
|
63
|
+
try {
|
|
64
|
+
const decoded = jwtDecode<TokenWithWallets>(token);
|
|
65
|
+
return decoded.crypto?.wallets ?? {};
|
|
66
|
+
} catch {
|
|
67
|
+
return {};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
21
70
|
|
|
22
|
-
|
|
23
|
-
|
|
71
|
+
/**
|
|
72
|
+
* Extracts all wallet addresses of a specific type from a JWT token.
|
|
73
|
+
*
|
|
74
|
+
* @param token - JWT access token or ID token string
|
|
75
|
+
* @param walletType - The wallet type to extract (e.g., "ethereum", "solana")
|
|
76
|
+
* @returns Array of wallet addresses, or empty array if none found
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* const addresses = getWalletAddresses(accessToken, 'ethereum');
|
|
81
|
+
* // ['0x1234...', '0x5678...']
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
export function getWalletAddresses(token: string, walletType: WalletType = "ethereum"): string[] {
|
|
85
|
+
const wallets = getWalletsFromToken(token);
|
|
86
|
+
return wallets[walletType]?.addresses ?? [];
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Checks if a user has any wallet addresses in their token.
|
|
91
|
+
*
|
|
92
|
+
* @param token - JWT access token or ID token string
|
|
93
|
+
* @returns true if the user has at least one wallet address
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* if (hasWallets(accessToken)) {
|
|
98
|
+
* // User authenticated with a wallet or has registered wallets
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export function hasWallets(token: string): boolean {
|
|
103
|
+
const wallets = getWalletsFromToken(token);
|
|
104
|
+
return Object.values(wallets).some((info) => info.addresses && info.addresses.length > 0);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets all wallet addresses across all chain types from a token.
|
|
109
|
+
*
|
|
110
|
+
* @param token - JWT access token or ID token string
|
|
111
|
+
* @returns Array of objects with walletType and address
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* const allWallets = getAllWalletAddresses(accessToken);
|
|
116
|
+
* // [
|
|
117
|
+
* // { walletType: 'ethereum', address: '0x1234...' },
|
|
118
|
+
* // { walletType: 'ethereum', address: '0x5678...' },
|
|
119
|
+
* // { walletType: 'solana', address: 'AbCd...' }
|
|
120
|
+
* // ]
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export function getAllWalletAddresses(
|
|
124
|
+
token: string,
|
|
125
|
+
): Array<{ walletType: string; address: string }> {
|
|
126
|
+
const wallets = getWalletsFromToken(token);
|
|
127
|
+
const result: Array<{ walletType: string; address: string }> = [];
|
|
128
|
+
|
|
129
|
+
for (const [walletType, info] of Object.entries(wallets)) {
|
|
130
|
+
if (info.addresses) {
|
|
131
|
+
for (const address of info.addresses) {
|
|
132
|
+
result.push({ walletType, address });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return result;
|
|
138
|
+
}
|
|
24
139
|
|
|
25
140
|
export function validOrRefreshableToken(
|
|
26
141
|
token?: string | false,
|
|
@@ -30,10 +145,7 @@ export function validOrRefreshableToken(
|
|
|
30
145
|
token?: string | boolean,
|
|
31
146
|
refreshToken?: string | boolean,
|
|
32
147
|
): string | boolean | undefined;
|
|
33
|
-
export function validOrRefreshableToken(
|
|
34
|
-
token?: string | boolean,
|
|
35
|
-
refreshToken?: string | boolean,
|
|
36
|
-
) {
|
|
148
|
+
export function validOrRefreshableToken(token?: string | boolean, refreshToken?: string | boolean) {
|
|
37
149
|
if (typeof token === "undefined") return;
|
|
38
150
|
if (!token) return false;
|
|
39
151
|
if (typeof token !== "string") return token;
|
|
@@ -56,7 +168,18 @@ export interface TokenParsed extends KeycloakTokenParsed {
|
|
|
56
168
|
typ?: "Bearer" | string;
|
|
57
169
|
}
|
|
58
170
|
|
|
59
|
-
|
|
171
|
+
/**
|
|
172
|
+
* Extended token interface that includes wallet claims from siwe-keycloak.
|
|
173
|
+
*/
|
|
174
|
+
export interface TokenWithWallets extends TokenParsed {
|
|
175
|
+
/**
|
|
176
|
+
* Crypto claim containing wallet addresses.
|
|
177
|
+
* Added by the siwe-wallet-mapper protocol mapper.
|
|
178
|
+
*/
|
|
179
|
+
crypto?: CryptoClaim;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface AccessTokenParsed extends TokenWithWallets {
|
|
60
183
|
email?: string;
|
|
61
184
|
email_verified?: boolean;
|
|
62
185
|
preferred_username?: string;
|
package/src/types.ts
CHANGED
|
@@ -1,24 +1,3 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* File: /src/types.ts
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 04-04-2024 15:50:39
|
|
5
|
-
* Author: Clay Risser
|
|
6
|
-
* -----
|
|
7
|
-
* BitSpur (c) Copyright 2021 - 2024
|
|
8
|
-
*
|
|
9
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
10
|
-
* you may not use this file except in compliance with the License.
|
|
11
|
-
* You may obtain a copy of the License at
|
|
12
|
-
*
|
|
13
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
14
|
-
*
|
|
15
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
16
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
17
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
18
|
-
* See the License for the specific language governing permissions and
|
|
19
|
-
* limitations under the License.
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
1
|
declare global {
|
|
23
2
|
interface Window {
|
|
24
3
|
ReactNativeWebView: {
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getProtoOf = Object.getPrototypeOf,
|
|
6
|
-
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all) __defProp(target, name, {
|
|
9
|
-
get: all[name],
|
|
10
|
-
enumerable: !0
|
|
11
|
-
});
|
|
12
|
-
},
|
|
13
|
-
__copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
15
|
-
get: () => from[key],
|
|
16
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
-
});
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
-
value: mod,
|
|
27
|
-
enumerable: !0
|
|
28
|
-
}) : target, mod)),
|
|
29
|
-
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
-
value: !0
|
|
31
|
-
}), mod);
|
|
32
|
-
var Authenticated_exports = {};
|
|
33
|
-
__export(Authenticated_exports, {
|
|
34
|
-
Authenticated: () => Authenticated,
|
|
35
|
-
withAuthenticated: () => withAuthenticated
|
|
36
|
-
});
|
|
37
|
-
module.exports = __toCommonJS(Authenticated_exports);
|
|
38
|
-
var import_async_storage = __toESM(require("@react-native-async-storage/async-storage")),
|
|
39
|
-
import_multiplatform = require("multiplatform.one"),
|
|
40
|
-
import_react = require("react"),
|
|
41
|
-
import_tamagui = require("tamagui"),
|
|
42
|
-
import_hooks = require("./hooks/index.cjs"),
|
|
43
|
-
import_keycloak = require("./keycloak/index.cjs"),
|
|
44
|
-
import_jsx_runtime = require("react/jsx-runtime");
|
|
45
|
-
global.AsyncStorage = import_async_storage.default;
|
|
46
|
-
function Authenticated({
|
|
47
|
-
children,
|
|
48
|
-
disabled,
|
|
49
|
-
loggedOutComponent,
|
|
50
|
-
loadingComponent
|
|
51
|
-
}) {
|
|
52
|
-
const authConfig = (0, import_hooks.useAuthConfig)(),
|
|
53
|
-
keycloak = (0, import_keycloak.useKeycloak)(),
|
|
54
|
-
tokensFromQuery = (0, import_hooks.useTokensFromQuery)();
|
|
55
|
-
if ((0, import_react.useEffect)(() => {
|
|
56
|
-
!keycloak || !authConfig.iframeSso && import_multiplatform.isIframe || import_multiplatform.isServer || keycloak.authenticated || tokensFromQuery || keycloak?.login({
|
|
57
|
-
redirectUri: authConfig.loginRedirectUri
|
|
58
|
-
});
|
|
59
|
-
}, [keycloak?.authenticated]), typeof disabled > "u" && (disabled = authConfig.disabled), disabled) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
60
|
-
children
|
|
61
|
-
});
|
|
62
|
-
if (typeof keycloak > "u") {
|
|
63
|
-
const LoadingComponent = loadingComponent;
|
|
64
|
-
return LoadingComponent ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(LoadingComponent, {}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
65
|
-
children: authConfig.debug ? "loading" : null
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
if (keycloak === null || keycloak.authenticated) return /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, {
|
|
69
|
-
children
|
|
70
|
-
});
|
|
71
|
-
const LoggedOutComponent = loggedOutComponent;
|
|
72
|
-
return LoggedOutComponent ? /* @__PURE__ */(0, import_jsx_runtime.jsx)(LoggedOutComponent, {}) : /* @__PURE__ */(0, import_jsx_runtime.jsx)(import_tamagui.Text, {
|
|
73
|
-
children: authConfig.debug ? "not authenticated" : null
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
function withAuthenticated(Component, options = {}) {
|
|
77
|
-
return props => /* @__PURE__ */(0, import_jsx_runtime.jsx)(Authenticated, {
|
|
78
|
-
...options,
|
|
79
|
-
children: /* @__PURE__ */(0, import_jsx_runtime.jsx)(Component, {
|
|
80
|
-
...props
|
|
81
|
-
})
|
|
82
|
-
});
|
|
83
|
-
}
|