@multiplatform.one/keycloak 5.0.27 → 6.0.1
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/dist/cjs/index.cjs
CHANGED
|
@@ -1,24 +1,888 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
1
3
|
var __defProp = Object.defineProperty;
|
|
2
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
5
12
|
var __copyProps = (to, from, except, desc) => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], 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", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
16
31
|
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
AfterAuth: () => AfterAuth,
|
|
34
|
+
AuthConfigContext: () => AuthConfigContext,
|
|
35
|
+
AuthProvider: () => AuthProvider,
|
|
36
|
+
Authenticated: () => Authenticated,
|
|
37
|
+
BaseKeycloak: () => BaseKeycloak,
|
|
38
|
+
Keycloak: () => Keycloak,
|
|
39
|
+
KeycloakConfigContext: () => KeycloakConfigContext,
|
|
40
|
+
KeycloakProvider: () => KeycloakProvider,
|
|
41
|
+
defaultAuthConfig: () => defaultAuthConfig,
|
|
42
|
+
getAllWalletAddresses: () => getAllWalletAddresses,
|
|
43
|
+
getWalletAddresses: () => getWalletAddresses,
|
|
44
|
+
getWalletsFromToken: () => getWalletsFromToken,
|
|
45
|
+
hasWallets: () => hasWallets,
|
|
46
|
+
isTokenExpired: () => isTokenExpired,
|
|
47
|
+
useAuthConfig: () => useAuthConfig,
|
|
48
|
+
useKeycloak: () => useKeycloak,
|
|
49
|
+
useSession: () => useSession,
|
|
50
|
+
useTokensFromQuery: () => useTokensFromQuery,
|
|
51
|
+
useTokensFromStore: () => useTokensFromStore,
|
|
52
|
+
validOrRefreshableToken: () => validOrRefreshableToken,
|
|
53
|
+
withAuthenticated: () => withAuthenticated
|
|
54
|
+
});
|
|
17
55
|
module.exports = __toCommonJS(index_exports);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
56
|
+
|
|
57
|
+
// src/Authenticated.tsx
|
|
58
|
+
var import_platform6 = require("@multiplatform.one/platform");
|
|
59
|
+
var import_react8 = require("react");
|
|
60
|
+
var import_tamagui = require("tamagui");
|
|
61
|
+
|
|
62
|
+
// src/hooks/useAuthConfig.ts
|
|
63
|
+
var import_react2 = require("react");
|
|
64
|
+
|
|
65
|
+
// src/authConfig.ts
|
|
66
|
+
var import_react = require("react");
|
|
67
|
+
var defaultAuthConfig = {};
|
|
68
|
+
var AuthConfigContext = (0, import_react.createContext)(defaultAuthConfig);
|
|
69
|
+
|
|
70
|
+
// src/hooks/useAuthConfig.ts
|
|
71
|
+
function useAuthConfig() {
|
|
72
|
+
return (0, import_react2.useContext)(AuthConfigContext);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/hooks/useTokensFromQuery/index.ts
|
|
76
|
+
var import_platform = require("@multiplatform.one/platform");
|
|
77
|
+
function useTokensFromQuery() {
|
|
78
|
+
const { iframeSso } = useAuthConfig();
|
|
79
|
+
if (iframeSso || !import_platform.isIframe) return false;
|
|
80
|
+
const query = new URLSearchParams(
|
|
81
|
+
typeof window === "undefined" ? "" : window?.location?.search || ""
|
|
82
|
+
);
|
|
83
|
+
return typeof query.get("idToken") === "string" || typeof query.get("token") === "string" || typeof query.get("refreshToken") === "string";
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// src/state.ts
|
|
87
|
+
var import_store = require("@multiplatform.one/store");
|
|
88
|
+
var import_platform2 = require("@multiplatform.one/platform");
|
|
89
|
+
var persist = import_platform2.isIframe || import_platform2.isTauri || !import_platform2.isBrowser && !import_platform2.isServer;
|
|
90
|
+
var authStore = (0, import_store.createStore)(
|
|
91
|
+
{ idToken: "", refreshToken: "", token: "" },
|
|
92
|
+
{ name: "auth", persist }
|
|
93
|
+
);
|
|
94
|
+
function useAuthStore() {
|
|
95
|
+
const state = (0, import_store.useStore)(authStore);
|
|
96
|
+
return {
|
|
97
|
+
...state,
|
|
98
|
+
setIdToken: (idToken) => authStore.setState((prev) => ({ ...prev, idToken })),
|
|
99
|
+
setRefreshToken: (refreshToken) => authStore.setState((prev) => ({ ...prev, refreshToken })),
|
|
100
|
+
setToken: (token) => authStore.setState((prev) => ({ ...prev, token })),
|
|
101
|
+
setTokens: (tokens) => authStore.setState((prev) => ({ ...prev, ...tokens }))
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// src/token.ts
|
|
106
|
+
var import_jwt_decode = require("jwt-decode");
|
|
107
|
+
function getWalletsFromToken(token) {
|
|
108
|
+
try {
|
|
109
|
+
const decoded = (0, import_jwt_decode.jwtDecode)(token);
|
|
110
|
+
return decoded.crypto?.wallets ?? {};
|
|
111
|
+
} catch {
|
|
112
|
+
return {};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function getWalletAddresses(token, walletType = "ethereum") {
|
|
116
|
+
const wallets = getWalletsFromToken(token);
|
|
117
|
+
return wallets[walletType]?.addresses ?? [];
|
|
118
|
+
}
|
|
119
|
+
function hasWallets(token) {
|
|
120
|
+
const wallets = getWalletsFromToken(token);
|
|
121
|
+
return Object.values(wallets).some((info) => info.addresses && info.addresses.length > 0);
|
|
122
|
+
}
|
|
123
|
+
function getAllWalletAddresses(token) {
|
|
124
|
+
const wallets = getWalletsFromToken(token);
|
|
125
|
+
const result = [];
|
|
126
|
+
for (const [walletType, info] of Object.entries(wallets)) {
|
|
127
|
+
if (info.addresses) {
|
|
128
|
+
for (const address of info.addresses) {
|
|
129
|
+
result.push({ walletType, address });
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return result;
|
|
134
|
+
}
|
|
135
|
+
function validOrRefreshableToken(token, refreshToken) {
|
|
136
|
+
if (typeof token === "undefined") return;
|
|
137
|
+
if (!token) return false;
|
|
138
|
+
if (typeof token !== "string") return token;
|
|
139
|
+
if (refreshToken) {
|
|
140
|
+
if (refreshToken === true || !isTokenExpired(refreshToken)) return token;
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
return isTokenExpired(token) ? false : token;
|
|
144
|
+
}
|
|
145
|
+
function isTokenExpired(token) {
|
|
146
|
+
const { exp } = (0, import_jwt_decode.jwtDecode)(token);
|
|
147
|
+
if (!exp) return false;
|
|
148
|
+
return Math.floor(Date.now() / 1e3) >= exp;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// src/hooks/useTokensFromState.ts
|
|
152
|
+
function useTokensFromStore() {
|
|
153
|
+
const authStore2 = useAuthStore();
|
|
154
|
+
return !!validOrRefreshableToken(authStore2.token, authStore2.refreshToken);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// src/keycloak/index.ts
|
|
158
|
+
var import_platform5 = require("@multiplatform.one/platform");
|
|
159
|
+
var import_react7 = require("react");
|
|
160
|
+
|
|
161
|
+
// src/betterAuth/client.ts
|
|
162
|
+
var import_react3 = require("better-auth/react");
|
|
163
|
+
var import_plugins = require("better-auth/client/plugins");
|
|
164
|
+
var import_platform3 = require("@multiplatform.one/platform");
|
|
165
|
+
var _client;
|
|
166
|
+
function getAuthClient(baseURL) {
|
|
167
|
+
if (_client) return _client;
|
|
168
|
+
_client = (0, import_react3.createAuthClient)({
|
|
169
|
+
baseURL: baseURL || (import_platform3.isWeb && typeof window !== "undefined" ? window.location.origin : ""),
|
|
170
|
+
plugins: [(0, import_plugins.genericOAuthClient)()]
|
|
171
|
+
});
|
|
172
|
+
return _client;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// src/session/index.ts
|
|
176
|
+
var import_platform4 = require("@multiplatform.one/platform");
|
|
177
|
+
var useSession = (_options) => {
|
|
178
|
+
return { session: null, status: "unauthenticated" };
|
|
179
|
+
};
|
|
180
|
+
if (import_platform4.isBrowser && !import_platform4.isTauri) {
|
|
181
|
+
useSession = (_options) => {
|
|
182
|
+
const client = getAuthClient();
|
|
183
|
+
const { data, isPending, error: _error } = client.useSession();
|
|
184
|
+
if (isPending) {
|
|
185
|
+
return { session: null, status: "loading" };
|
|
186
|
+
}
|
|
187
|
+
if (!data?.user) {
|
|
188
|
+
return { session: null, status: "unauthenticated" };
|
|
189
|
+
}
|
|
190
|
+
return {
|
|
191
|
+
session: {
|
|
192
|
+
user: data.user,
|
|
193
|
+
expires: data.session?.expiresAt?.toString()
|
|
194
|
+
},
|
|
195
|
+
status: "authenticated"
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
// src/keycloak/base.ts
|
|
201
|
+
var import_jwt_decode2 = require("jwt-decode");
|
|
202
|
+
var import_react5 = require("react");
|
|
203
|
+
|
|
204
|
+
// src/keycloak/context.ts
|
|
205
|
+
var import_react4 = require("react");
|
|
206
|
+
var KeycloakContext = (0, import_react4.createContext)(void 0);
|
|
207
|
+
|
|
208
|
+
// src/keycloak/base.ts
|
|
209
|
+
var BaseKeycloak = class {
|
|
210
|
+
constructor(config, input, idToken, refreshToken, login, logout) {
|
|
211
|
+
this.config = config;
|
|
212
|
+
this.authenticated = false;
|
|
213
|
+
this.clientId = this.config.clientId;
|
|
214
|
+
this.realm = this.config.realm;
|
|
215
|
+
if (typeof input === "string") {
|
|
216
|
+
this.token = input;
|
|
217
|
+
this.idToken = idToken;
|
|
218
|
+
this.refreshToken = refreshToken;
|
|
219
|
+
this._parseTokens();
|
|
220
|
+
} else if (typeof input === "object") {
|
|
221
|
+
this._handleInputObject(input);
|
|
222
|
+
}
|
|
223
|
+
this._login = login;
|
|
224
|
+
this._logout = logout;
|
|
225
|
+
this._sync();
|
|
226
|
+
}
|
|
227
|
+
_handleInputObject(input) {
|
|
228
|
+
if (typeof input.init === "function") {
|
|
229
|
+
this._keycloakClient = input;
|
|
230
|
+
} else {
|
|
231
|
+
this._mock = input;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
_parseTokens() {
|
|
235
|
+
if (this.token && !this.tokenParsed) {
|
|
236
|
+
this.tokenParsed = (0, import_jwt_decode2.jwtDecode)(this.token);
|
|
237
|
+
}
|
|
238
|
+
if (this.idToken && !this.idTokenParsed) {
|
|
239
|
+
this.idTokenParsed = (0, import_jwt_decode2.jwtDecode)(this.idToken);
|
|
240
|
+
}
|
|
241
|
+
if (this.refreshToken && !this.refreshTokenParsed) {
|
|
242
|
+
this.refreshTokenParsed = (0, import_jwt_decode2.jwtDecode)(this.refreshToken);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
_clear() {
|
|
246
|
+
this.authenticated = false;
|
|
247
|
+
this.email = void 0;
|
|
248
|
+
this.idToken = void 0;
|
|
249
|
+
this.idTokenParsed = void 0;
|
|
250
|
+
this.realmAccess = void 0;
|
|
251
|
+
this.refreshToken = void 0;
|
|
252
|
+
this.refreshTokenParsed = void 0;
|
|
253
|
+
this.resourceAccess = void 0;
|
|
254
|
+
this.sessionId = void 0;
|
|
255
|
+
this.subject = void 0;
|
|
256
|
+
this.token = void 0;
|
|
257
|
+
this.tokenParsed = void 0;
|
|
258
|
+
this.username = void 0;
|
|
259
|
+
}
|
|
260
|
+
_sync() {
|
|
261
|
+
if (this._mock) {
|
|
262
|
+
this.authenticated = true;
|
|
263
|
+
this.email = this._mock.email;
|
|
264
|
+
this.username = this._mock.username;
|
|
265
|
+
} else if (this._keycloakClient) {
|
|
266
|
+
this.authenticated = !!this._keycloakClient.authenticated;
|
|
267
|
+
this.email = this._keycloakClient?.tokenParsed?.email;
|
|
268
|
+
this.idToken = this._keycloakClient?.idToken;
|
|
269
|
+
this.idTokenParsed = this._keycloakClient?.idTokenParsed;
|
|
270
|
+
this.realmAccess = this._keycloakClient?.realmAccess;
|
|
271
|
+
this.refreshToken = this._keycloakClient?.refreshToken;
|
|
272
|
+
this.refreshTokenParsed = this._keycloakClient?.refreshTokenParsed;
|
|
273
|
+
this.resourceAccess = this._keycloakClient?.resourceAccess;
|
|
274
|
+
this.sessionId = this._keycloakClient?.sessionId;
|
|
275
|
+
this.subject = this._keycloakClient?.subject;
|
|
276
|
+
this.token = this._keycloakClient?.token;
|
|
277
|
+
this.tokenParsed = this._keycloakClient?.tokenParsed;
|
|
278
|
+
this.username = this.tokenParsed?.preferred_username;
|
|
279
|
+
if (this._keycloakClient.realm) this.realm = this._keycloakClient.realm;
|
|
280
|
+
if (this._keycloakClient.clientId) {
|
|
281
|
+
this.clientId = this._keycloakClient.clientId;
|
|
282
|
+
}
|
|
283
|
+
} else if (this.tokenParsed) {
|
|
284
|
+
this.clientId = this.tokenParsed.azp || this.config.clientId;
|
|
285
|
+
this.email = this.tokenParsed.email;
|
|
286
|
+
this.realm = this.tokenParsed.iss?.split("/").pop() || this.config.realm;
|
|
287
|
+
this.realmAccess = this.tokenParsed.realm_access;
|
|
288
|
+
this.resourceAccess = this.tokenParsed.resource_access;
|
|
289
|
+
this.sessionId = this.tokenParsed.session_state;
|
|
290
|
+
this.subject = this.tokenParsed.sub;
|
|
291
|
+
this.authenticated = !!(this.tokenParsed?.exp && this.idToken && this.tokenParsed.exp > Date.now() / 1e3);
|
|
292
|
+
this.username = this.tokenParsed?.preferred_username;
|
|
293
|
+
} else {
|
|
294
|
+
return this._clear();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
async getUserInfo() {
|
|
298
|
+
if (!this.authenticated) return;
|
|
299
|
+
const response = await fetch(
|
|
300
|
+
`${this.config.url}/realms/${this.realm}/protocol/openid-connect/userinfo`,
|
|
301
|
+
{
|
|
302
|
+
method: "GET",
|
|
303
|
+
headers: {
|
|
304
|
+
Authorization: `Bearer ${this.token}`,
|
|
305
|
+
Accept: "application/json"
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
);
|
|
309
|
+
if (response.ok) return response.json();
|
|
310
|
+
}
|
|
311
|
+
async login(options = {}) {
|
|
312
|
+
this._clear();
|
|
313
|
+
if (this._keycloakClient) {
|
|
314
|
+
await this._keycloakClient.login(options);
|
|
315
|
+
} else {
|
|
316
|
+
await this._login?.(options);
|
|
317
|
+
}
|
|
318
|
+
this._sync();
|
|
319
|
+
}
|
|
320
|
+
async logout(options = {}) {
|
|
321
|
+
if (this._keycloakClient) {
|
|
322
|
+
await this._keycloakClient.logout(options);
|
|
323
|
+
} else {
|
|
324
|
+
await this._logout?.(options);
|
|
325
|
+
}
|
|
326
|
+
this._clear();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
|
|
330
|
+
// src/keycloak/config.ts
|
|
331
|
+
var import_react6 = require("react");
|
|
332
|
+
var KeycloakConfigContext = (0, import_react6.createContext)({
|
|
333
|
+
clientId: "",
|
|
334
|
+
realm: "",
|
|
335
|
+
url: ""
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
// src/keycloak/index.ts
|
|
339
|
+
var Keycloak = class extends BaseKeycloak {
|
|
340
|
+
_handleInputObject(input) {
|
|
341
|
+
if (typeof input.init === "function") {
|
|
342
|
+
this._keycloakClient = input;
|
|
343
|
+
} else if (input.accessToken) {
|
|
344
|
+
const session = input;
|
|
345
|
+
this.token = session.accessToken;
|
|
346
|
+
this.idToken = session.idToken;
|
|
347
|
+
this.refreshToken = session.refreshToken;
|
|
348
|
+
this._parseTokens();
|
|
349
|
+
} else {
|
|
350
|
+
this._mock = input;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
async login(options = {}) {
|
|
354
|
+
this._clear();
|
|
355
|
+
if (this._keycloakClient) {
|
|
356
|
+
await this._keycloakClient.login(options);
|
|
357
|
+
} else if (import_platform5.isBrowser && !import_platform5.isServer) {
|
|
358
|
+
const client = getAuthClient();
|
|
359
|
+
await client.signIn.social({
|
|
360
|
+
provider: "keycloak",
|
|
361
|
+
callbackURL: options.redirectUri || (import_platform5.isWeb ? window.location.href : "")
|
|
362
|
+
});
|
|
363
|
+
} else {
|
|
364
|
+
await this._login?.(options);
|
|
365
|
+
}
|
|
366
|
+
this._sync();
|
|
367
|
+
}
|
|
368
|
+
async logout(options = {}) {
|
|
369
|
+
if (this._keycloakClient) {
|
|
370
|
+
await this._keycloakClient.logout(options);
|
|
371
|
+
} else if (import_platform5.isBrowser && !import_platform5.isServer) {
|
|
372
|
+
const client = getAuthClient();
|
|
373
|
+
await client.signOut({
|
|
374
|
+
fetchOptions: {
|
|
375
|
+
onSuccess: () => {
|
|
376
|
+
if (options.redirectUri) {
|
|
377
|
+
if (import_platform5.isWeb) window.location.href = options.redirectUri;
|
|
378
|
+
} else {
|
|
379
|
+
if (import_platform5.isWeb) window.location.reload();
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
});
|
|
384
|
+
} else {
|
|
385
|
+
await this._logout?.(options);
|
|
386
|
+
}
|
|
387
|
+
this._clear();
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
function useKeycloak() {
|
|
391
|
+
const keycloak = (0, import_react7.useContext)(KeycloakContext);
|
|
392
|
+
const keycloakConfig = (0, import_react7.useContext)(KeycloakConfigContext);
|
|
393
|
+
const { disabled } = useAuthConfig();
|
|
394
|
+
if (disabled) return null;
|
|
395
|
+
if (keycloak) return keycloak;
|
|
396
|
+
const { session, status } = useSession();
|
|
397
|
+
if (import_platform5.isStorybook) {
|
|
398
|
+
return new Keycloak(keycloakConfig, {
|
|
399
|
+
email: "storybook@example.com",
|
|
400
|
+
username: "storybook"
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
if (status === "unauthenticated") {
|
|
404
|
+
return new Keycloak(keycloakConfig);
|
|
405
|
+
}
|
|
406
|
+
if (status === "authenticated") {
|
|
407
|
+
if (session?.accessToken) {
|
|
408
|
+
return new Keycloak(keycloakConfig, session);
|
|
409
|
+
}
|
|
410
|
+
return new Keycloak(keycloakConfig);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/Authenticated.tsx
|
|
415
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
416
|
+
function Authenticated({
|
|
417
|
+
children,
|
|
418
|
+
disabled,
|
|
419
|
+
loggedOutComponent,
|
|
420
|
+
loadingComponent
|
|
421
|
+
}) {
|
|
422
|
+
const authConfig = useAuthConfig();
|
|
423
|
+
const keycloak = useKeycloak();
|
|
424
|
+
const tokensFromQuery = useTokensFromQuery();
|
|
425
|
+
(0, import_react8.useEffect)(() => {
|
|
426
|
+
if (!keycloak || !authConfig.iframeSso && import_platform6.isIframe || import_platform6.isServer || keycloak.authenticated || tokensFromQuery) {
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
keycloak?.login({
|
|
430
|
+
redirectUri: authConfig.loginRedirectUri
|
|
431
|
+
});
|
|
432
|
+
}, [keycloak?.authenticated]);
|
|
433
|
+
if (typeof disabled === "undefined") disabled = authConfig.disabled;
|
|
434
|
+
if (disabled) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
435
|
+
if (typeof keycloak === "undefined") {
|
|
436
|
+
const LoadingComponent = loadingComponent;
|
|
437
|
+
return LoadingComponent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoadingComponent, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Text, { children: authConfig.debug ? "loading" : null });
|
|
438
|
+
}
|
|
439
|
+
if (keycloak === null || keycloak.authenticated) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_jsx_runtime.Fragment, { children });
|
|
440
|
+
const LoggedOutComponent = loggedOutComponent;
|
|
441
|
+
return LoggedOutComponent ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LoggedOutComponent, {}) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tamagui.Text, { children: authConfig.debug ? "not authenticated" : null });
|
|
442
|
+
}
|
|
443
|
+
function withAuthenticated(Component, options = {}) {
|
|
444
|
+
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Authenticated, { ...options, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }) });
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// src/provider/AfterAuth.tsx
|
|
448
|
+
var import_logger = require("@multiplatform.one/logger");
|
|
449
|
+
var import_react9 = require("react");
|
|
450
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
451
|
+
function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
452
|
+
const authConfig = useAuthConfig();
|
|
453
|
+
const authStore2 = useAuthStore();
|
|
454
|
+
const keycloak = useKeycloak();
|
|
455
|
+
(0, import_react9.useEffect)(() => {
|
|
456
|
+
if (!persist || !keycloak?.authenticated) return;
|
|
457
|
+
if (keycloak.token) {
|
|
458
|
+
authStore2.setTokens({
|
|
459
|
+
token: keycloak.token,
|
|
460
|
+
...keycloak.idToken && { idToken: keycloak.idToken },
|
|
461
|
+
...keycloak.refreshToken && {
|
|
462
|
+
refreshToken: keycloak.refreshToken
|
|
463
|
+
}
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
}, [
|
|
467
|
+
authStore2,
|
|
468
|
+
persist,
|
|
469
|
+
keycloak?.authenticated,
|
|
470
|
+
keycloak?.token,
|
|
471
|
+
keycloak?.idToken,
|
|
472
|
+
keycloak?.refreshToken
|
|
473
|
+
]);
|
|
474
|
+
(0, import_react9.useEffect)(() => {
|
|
475
|
+
if (authConfig.debug && keycloak?.token) {
|
|
476
|
+
import_logger.logger.debug("token", keycloak.token);
|
|
477
|
+
}
|
|
478
|
+
}, [authConfig.debug, keycloak?.token]);
|
|
479
|
+
(0, import_react9.useEffect)(() => {
|
|
480
|
+
if (authConfig.debug && keycloak?.idToken) {
|
|
481
|
+
import_logger.logger.debug("idToken", keycloak.idToken);
|
|
482
|
+
}
|
|
483
|
+
}, [authConfig.debug, keycloak?.idToken]);
|
|
484
|
+
(0, import_react9.useEffect)(() => {
|
|
485
|
+
if (authConfig.debug && keycloak?.refreshToken) {
|
|
486
|
+
import_logger.logger.debug("refreshToken", keycloak.refreshToken);
|
|
487
|
+
}
|
|
488
|
+
}, [authConfig.debug, keycloak?.refreshToken]);
|
|
489
|
+
(0, import_react9.useEffect)(() => {
|
|
490
|
+
if (authConfig.debug && keycloak?.authenticated) {
|
|
491
|
+
import_logger.logger.debug("authenticated", keycloak.authenticated);
|
|
492
|
+
}
|
|
493
|
+
}, [authConfig.debug, keycloak?.authenticated]);
|
|
494
|
+
(0, import_react9.useEffect)(() => {
|
|
495
|
+
if (authConfig.debug && keycloak === null) {
|
|
496
|
+
import_logger.logger.debug("keycloak disabled");
|
|
497
|
+
}
|
|
498
|
+
}, [authConfig.debug, keycloak]);
|
|
499
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children });
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
// src/provider/authProvider/index.tsx
|
|
503
|
+
var import_keycloak_js = __toESM(require("@multiplatform.one/keycloak-js"));
|
|
504
|
+
var import_platform7 = require("@multiplatform.one/platform");
|
|
505
|
+
var import_logger2 = require("@multiplatform.one/logger");
|
|
506
|
+
var import_react10 = require("react");
|
|
507
|
+
|
|
508
|
+
// src/Loading.tsx
|
|
509
|
+
var import_tamagui2 = require("tamagui");
|
|
510
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
511
|
+
function Loading({ loadingComponent }) {
|
|
512
|
+
const { debug } = useAuthConfig();
|
|
513
|
+
const LoadingComponent = loadingComponent;
|
|
514
|
+
if (typeof LoadingComponent === "undefined") {
|
|
515
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_tamagui2.Text, { children: debug ? "loading" : null });
|
|
516
|
+
}
|
|
517
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(LoadingComponent, {});
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// src/provider/authProvider/shared.ts
|
|
521
|
+
var defaultKeycloakInitOptions = {
|
|
522
|
+
checkLoginIframe: true,
|
|
523
|
+
checkLoginIframeInterval: 5,
|
|
524
|
+
enableLogging: false,
|
|
525
|
+
onLoad: "check-sso",
|
|
526
|
+
pkceMethod: "S256"
|
|
527
|
+
};
|
|
528
|
+
|
|
529
|
+
// src/provider/authProvider/index.tsx
|
|
530
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
531
|
+
function AuthProvider({
|
|
532
|
+
children,
|
|
533
|
+
disabled,
|
|
534
|
+
keycloakConfig,
|
|
535
|
+
keycloakInitOptions,
|
|
536
|
+
loadingComponent
|
|
537
|
+
}) {
|
|
538
|
+
const { debug, messageHandlerKeys, iframeSso } = useAuthConfig();
|
|
539
|
+
const query = new URLSearchParams(import_platform7.isWindowDefined ? window?.location?.search || "" : "");
|
|
540
|
+
const authStore2 = useAuthStore();
|
|
541
|
+
const [keycloak, setKeycloak] = (0, import_react10.useState)();
|
|
542
|
+
const idTokenQuery = query.get("idToken");
|
|
543
|
+
const refreshTokenQuery = query.get("refreshToken");
|
|
544
|
+
const tokenQuery = query.get("token");
|
|
545
|
+
const [listeningRefreshToken, setListeningRefreshToken] = (0, import_react10.useState)(false);
|
|
546
|
+
const [listeningToken, setListeningToken] = (0, import_react10.useState)(false);
|
|
547
|
+
const [listeningIdToken, setListeningIdToken] = (0, import_react10.useState)(false);
|
|
548
|
+
const [loadedMessagePosted, setLoadedMessagePosted] = (0, import_react10.useState)(false);
|
|
549
|
+
const initialRefreshTokenQuery = (0, import_react10.useMemo)(
|
|
550
|
+
() => validOrRefreshableToken(
|
|
551
|
+
!iframeSso && import_platform7.isIframe || typeof refreshTokenQuery === "string" ? refreshTokenQuery || true : void 0
|
|
552
|
+
),
|
|
553
|
+
[refreshTokenQuery, iframeSso]
|
|
554
|
+
);
|
|
555
|
+
const initialIdTokenQuery = (0, import_react10.useMemo)(
|
|
556
|
+
() => validOrRefreshableToken(
|
|
557
|
+
!iframeSso && import_platform7.isIframe || typeof idTokenQuery === "string" ? idTokenQuery || true : void 0,
|
|
558
|
+
initialRefreshTokenQuery
|
|
559
|
+
),
|
|
560
|
+
[idTokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
561
|
+
);
|
|
562
|
+
const initialTokenQuery = (0, import_react10.useMemo)(
|
|
563
|
+
() => validOrRefreshableToken(
|
|
564
|
+
import_platform7.isIframe ? typeof tokenQuery === "string" ? tokenQuery || true : void 0 : void 0,
|
|
565
|
+
initialRefreshTokenQuery
|
|
566
|
+
),
|
|
567
|
+
[tokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
568
|
+
);
|
|
569
|
+
const [tokens, setTokens] = (0, import_react10.useState)({
|
|
570
|
+
refreshToken: initialRefreshTokenQuery,
|
|
571
|
+
token: initialTokenQuery,
|
|
572
|
+
idToken: initialIdTokenQuery
|
|
573
|
+
});
|
|
574
|
+
const authSource = (0, import_react10.useMemo)(() => {
|
|
575
|
+
if (!iframeSso && import_platform7.isIframe) {
|
|
576
|
+
if (initialTokenQuery) return "query" /* Query */;
|
|
577
|
+
return "store" /* Store */;
|
|
578
|
+
}
|
|
579
|
+
return "session" /* Session */;
|
|
580
|
+
}, [initialTokenQuery, iframeSso]);
|
|
581
|
+
const authStrategy = (0, import_react10.useMemo)(() => {
|
|
582
|
+
if (authSource === "session" /* Session */) return "better-auth" /* BetterAuth */;
|
|
583
|
+
if (authSource === "query" /* Query */) {
|
|
584
|
+
return "keycloak-client-implicit" /* KeycloakClientImplicit */;
|
|
585
|
+
}
|
|
586
|
+
if (!persist) return "keycloak-client-standard" /* KeycloakClientStandard */;
|
|
587
|
+
if (authStore2.token && typeof tokens.token === "string" && tokens.token) {
|
|
588
|
+
return "keycloak-client-implicit" /* KeycloakClientImplicit */;
|
|
589
|
+
}
|
|
590
|
+
return "keycloak-client-standard" /* KeycloakClientStandard */;
|
|
591
|
+
}, [authSource, authStore2.token, tokens.token]);
|
|
592
|
+
const isLoading = (0, import_react10.useMemo)(() => {
|
|
593
|
+
if (!authStrategy) return true;
|
|
594
|
+
if (authStrategy === "keycloak-client-implicit" /* KeycloakClientImplicit */) {
|
|
595
|
+
if (authSource === "query" /* Query */ && (initialRefreshTokenQuery === true || initialTokenQuery === true || initialIdTokenQuery === true)) {
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return false;
|
|
600
|
+
}, [
|
|
601
|
+
authSource,
|
|
602
|
+
authStore2.idToken,
|
|
603
|
+
authStore2.refreshToken,
|
|
604
|
+
authStore2.token,
|
|
605
|
+
authStrategy,
|
|
606
|
+
initialIdTokenQuery,
|
|
607
|
+
initialRefreshTokenQuery,
|
|
608
|
+
initialTokenQuery
|
|
609
|
+
]);
|
|
610
|
+
(0, import_react10.useEffect)(() => {
|
|
611
|
+
if (!persist || tokens.idToken || tokens.refreshToken || tokens.token) {
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
const refreshToken = validOrRefreshableToken(authStore2.refreshToken);
|
|
615
|
+
const idToken = validOrRefreshableToken(authStore2.idToken, refreshToken);
|
|
616
|
+
const token = validOrRefreshableToken(authStore2.token, refreshToken);
|
|
617
|
+
if (!idToken && !refreshToken && !token) return;
|
|
618
|
+
setTokens({
|
|
619
|
+
idToken,
|
|
620
|
+
refreshToken,
|
|
621
|
+
token
|
|
622
|
+
});
|
|
623
|
+
}, [authStore2, persist]);
|
|
624
|
+
(0, import_react10.useEffect)(() => {
|
|
625
|
+
if (disabled || authSource !== "query" /* Query */ || tokens.token === true || tokens.refreshToken === true || tokens.idToken === true || loadedMessagePosted) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
if (debug) import_logger2.logger.debug("post message", JSON.stringify({ type: "LOADED" }));
|
|
629
|
+
(messageHandlerKeys || []).forEach((key) => {
|
|
630
|
+
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
631
|
+
});
|
|
632
|
+
window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
633
|
+
window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
634
|
+
setLoadedMessagePosted(true);
|
|
635
|
+
}, [disabled, authSource, tokens.token, tokens.refreshToken, tokens.idToken]);
|
|
636
|
+
(0, import_react10.useEffect)(() => {
|
|
637
|
+
if (disabled || tokens.refreshToken !== true || listeningRefreshToken) {
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
setListeningRefreshToken(true);
|
|
641
|
+
function messageCallback(e) {
|
|
642
|
+
let data = e?.data || null;
|
|
643
|
+
if (typeof data === "string") {
|
|
644
|
+
try {
|
|
645
|
+
data = JSON.parse(data);
|
|
646
|
+
} catch {
|
|
647
|
+
}
|
|
648
|
+
}
|
|
649
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
650
|
+
const message = data;
|
|
651
|
+
if (!message.type) return;
|
|
652
|
+
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
653
|
+
if (debug) import_logger2.logger.debug("setting refresh token", message.payload);
|
|
654
|
+
setTokens((tokens2) => ({
|
|
655
|
+
...tokens2,
|
|
656
|
+
refreshToken: validOrRefreshableToken(message.payload)
|
|
657
|
+
}));
|
|
658
|
+
window.removeEventListener("message", messageCallback);
|
|
659
|
+
setListeningRefreshToken(false);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
if (debug) {
|
|
663
|
+
import_logger2.logger.debug(
|
|
664
|
+
"listening for message",
|
|
665
|
+
JSON.stringify({
|
|
666
|
+
type: "REFRESH_TOKEN",
|
|
667
|
+
payload: "<some_refresh_token>"
|
|
668
|
+
})
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
window.addEventListener("message", messageCallback);
|
|
672
|
+
return () => {
|
|
673
|
+
window.removeEventListener("message", messageCallback);
|
|
674
|
+
};
|
|
675
|
+
}, [disabled, tokens.refreshToken, listeningRefreshToken]);
|
|
676
|
+
(0, import_react10.useEffect)(() => {
|
|
677
|
+
if (disabled || tokens.token !== true || listeningToken) return;
|
|
678
|
+
setListeningToken(true);
|
|
679
|
+
function messageCallback(e) {
|
|
680
|
+
let data = e?.data || null;
|
|
681
|
+
if (typeof data === "string") {
|
|
682
|
+
try {
|
|
683
|
+
data = JSON.parse(data);
|
|
684
|
+
} catch {
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
688
|
+
const message = data;
|
|
689
|
+
if (!message.type) return;
|
|
690
|
+
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
691
|
+
if (debug) import_logger2.logger.debug("setting token", message.payload);
|
|
692
|
+
setTokens((tokens2) => ({
|
|
693
|
+
...tokens2,
|
|
694
|
+
token: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
695
|
+
}));
|
|
696
|
+
window.removeEventListener("message", messageCallback);
|
|
697
|
+
setListeningToken(false);
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
if (debug) {
|
|
701
|
+
import_logger2.logger.debug(
|
|
702
|
+
"listening for message",
|
|
703
|
+
JSON.stringify({
|
|
704
|
+
type: "TOKEN",
|
|
705
|
+
payload: "<some_token>"
|
|
706
|
+
})
|
|
707
|
+
);
|
|
708
|
+
}
|
|
709
|
+
window.addEventListener("message", messageCallback);
|
|
710
|
+
return () => {
|
|
711
|
+
window.removeEventListener("message", messageCallback);
|
|
712
|
+
};
|
|
713
|
+
}, [disabled, tokens.token, listeningToken]);
|
|
714
|
+
(0, import_react10.useEffect)(() => {
|
|
715
|
+
if (disabled || tokens.idToken !== true || listeningIdToken) return;
|
|
716
|
+
setListeningIdToken(true);
|
|
717
|
+
function messageCallback(e) {
|
|
718
|
+
let data = e?.data || null;
|
|
719
|
+
if (typeof data === "string") {
|
|
720
|
+
try {
|
|
721
|
+
data = JSON.parse(data);
|
|
722
|
+
} catch {
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
726
|
+
const message = data;
|
|
727
|
+
if (!message.type) return;
|
|
728
|
+
if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
|
|
729
|
+
if (debug) import_logger2.logger.debug("setting id token", message.payload);
|
|
730
|
+
setTokens((tokens2) => ({
|
|
731
|
+
...tokens2,
|
|
732
|
+
idToken: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
733
|
+
}));
|
|
734
|
+
window.removeEventListener("message", messageCallback);
|
|
735
|
+
setListeningIdToken(false);
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (debug) {
|
|
739
|
+
import_logger2.logger.debug(
|
|
740
|
+
"listening for message",
|
|
741
|
+
JSON.stringify({
|
|
742
|
+
type: "ID_TOKEN",
|
|
743
|
+
payload: "<some_id_token>"
|
|
744
|
+
})
|
|
745
|
+
);
|
|
746
|
+
}
|
|
747
|
+
window.addEventListener("message", messageCallback);
|
|
748
|
+
return () => {
|
|
749
|
+
window.removeEventListener("message", messageCallback);
|
|
750
|
+
};
|
|
751
|
+
}, [disabled, tokens.idToken, listeningIdToken]);
|
|
752
|
+
const keycloakClient = (0, import_react10.useMemo)(
|
|
753
|
+
() => !disabled && !isLoading && (authStrategy === "keycloak-client-standard" /* KeycloakClientStandard */ || authStrategy === "keycloak-client-implicit" /* KeycloakClientImplicit */) && keycloakConfig ? new import_keycloak_js.default({
|
|
754
|
+
clientId: keycloakConfig.publicClientId || keycloakConfig.clientId,
|
|
755
|
+
realm: keycloakConfig.realm,
|
|
756
|
+
url: keycloakConfig.url
|
|
757
|
+
}) : void 0,
|
|
758
|
+
[
|
|
759
|
+
authStrategy,
|
|
760
|
+
disabled,
|
|
761
|
+
isLoading,
|
|
762
|
+
keycloakConfig,
|
|
763
|
+
keycloakInitOptions,
|
|
764
|
+
tokens.idToken,
|
|
765
|
+
tokens.refreshToken,
|
|
766
|
+
tokens.token
|
|
767
|
+
]
|
|
768
|
+
);
|
|
769
|
+
const initOptions = (0, import_react10.useMemo)(() => {
|
|
770
|
+
if (!keycloakClient) return;
|
|
771
|
+
const initOptions2 = {
|
|
772
|
+
...defaultKeycloakInitOptions,
|
|
773
|
+
...keycloakInitOptions,
|
|
774
|
+
scope: [
|
|
775
|
+
.../* @__PURE__ */ new Set([
|
|
776
|
+
"email",
|
|
777
|
+
"openid",
|
|
778
|
+
"profile",
|
|
779
|
+
...defaultKeycloakInitOptions.scope?.split(" ") || [],
|
|
780
|
+
...keycloakInitOptions?.scope?.split(" ") || [],
|
|
781
|
+
...keycloakConfig.scopes || []
|
|
782
|
+
])
|
|
783
|
+
].join(" ")
|
|
784
|
+
};
|
|
785
|
+
if (debug) initOptions2.enableLogging = true;
|
|
786
|
+
if (tokens.token && typeof tokens.token === "string") {
|
|
787
|
+
initOptions2.token = tokens.token;
|
|
788
|
+
initOptions2.timeSkew = 0;
|
|
789
|
+
if (tokens.idToken && typeof tokens.idToken === "string") {
|
|
790
|
+
initOptions2.idToken = tokens.idToken;
|
|
791
|
+
}
|
|
792
|
+
if (tokens.refreshToken && typeof tokens.refreshToken === "string") {
|
|
793
|
+
initOptions2.refreshToken = tokens.refreshToken;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
if (!iframeSso && import_platform7.isIframe || tokens.token && !tokens.refreshToken) {
|
|
797
|
+
initOptions2.checkLoginIframe = false;
|
|
798
|
+
initOptions2.flow = "implicit";
|
|
799
|
+
initOptions2.onLoad = void 0;
|
|
800
|
+
}
|
|
801
|
+
return initOptions2;
|
|
802
|
+
}, [
|
|
803
|
+
keycloakClient,
|
|
804
|
+
keycloakInitOptions,
|
|
805
|
+
keycloakConfig.scopes,
|
|
806
|
+
debug,
|
|
807
|
+
tokens.token,
|
|
808
|
+
tokens.idToken,
|
|
809
|
+
tokens.refreshToken,
|
|
810
|
+
iframeSso
|
|
811
|
+
]);
|
|
812
|
+
(0, import_react10.useEffect)(() => {
|
|
813
|
+
if (!keycloakClient || !initOptions || authStrategy === "keycloak-client-implicit" /* KeycloakClientImplicit */ && (typeof tokens.token !== "string" || !tokens.token)) {
|
|
814
|
+
return;
|
|
815
|
+
}
|
|
816
|
+
function onError() {
|
|
817
|
+
if (keycloakClient && initOptions) {
|
|
818
|
+
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
function onUpdate() {
|
|
822
|
+
if (keycloakClient && initOptions) {
|
|
823
|
+
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
(async () => {
|
|
827
|
+
keycloakClient.onAuthError = onError;
|
|
828
|
+
keycloakClient.onAuthLogout = onUpdate;
|
|
829
|
+
keycloakClient.onAuthRefreshError = onError;
|
|
830
|
+
keycloakClient.onAuthRefreshSuccess = onUpdate;
|
|
831
|
+
keycloakClient.onAuthSuccess = onUpdate;
|
|
832
|
+
keycloakClient.onReady = onUpdate;
|
|
833
|
+
keycloakClient.onTokenExpired = async () => {
|
|
834
|
+
try {
|
|
835
|
+
await keycloakClient.updateToken(5);
|
|
836
|
+
} catch (err) {
|
|
837
|
+
import_logger2.logger.warn(err);
|
|
838
|
+
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
839
|
+
}
|
|
840
|
+
};
|
|
841
|
+
await keycloakClient.init(initOptions);
|
|
842
|
+
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
843
|
+
})();
|
|
844
|
+
}, [keycloakClient, initOptions, authStrategy, tokens.token]);
|
|
845
|
+
const render = (0, import_react10.useCallback)(
|
|
846
|
+
() => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(KeycloakConfigContext.Provider, { value: keycloakConfig, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(KeycloakContext.Provider, { value: keycloak, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AfterAuth, { loadingComponent, children }) }) }),
|
|
847
|
+
[children, keycloak, keycloakConfig]
|
|
848
|
+
);
|
|
849
|
+
if (disabled) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children });
|
|
850
|
+
if (authStrategy === "better-auth" /* BetterAuth */) {
|
|
851
|
+
return render();
|
|
852
|
+
}
|
|
853
|
+
if (isLoading) return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Loading, { loadingComponent });
|
|
854
|
+
return render();
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
// src/provider/KeycloakProvider.tsx
|
|
858
|
+
var import_react11 = require("react");
|
|
859
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
860
|
+
function KeycloakProvider({
|
|
861
|
+
baseUrl,
|
|
862
|
+
children,
|
|
863
|
+
clientId,
|
|
864
|
+
loginRedirectUri,
|
|
865
|
+
debug,
|
|
866
|
+
disabled,
|
|
867
|
+
iframeSso,
|
|
868
|
+
publicClientId,
|
|
869
|
+
realm
|
|
870
|
+
}) {
|
|
871
|
+
const authConfig = (0, import_react11.useMemo)(
|
|
872
|
+
() => ({ debug, disabled, iframeSso, loginRedirectUri }),
|
|
873
|
+
[debug, disabled, iframeSso, loginRedirectUri]
|
|
874
|
+
);
|
|
875
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AuthConfigContext.Provider, { value: authConfig, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
876
|
+
AuthProvider,
|
|
877
|
+
{
|
|
878
|
+
disabled,
|
|
879
|
+
keycloakConfig: {
|
|
880
|
+
clientId: clientId || "app",
|
|
881
|
+
publicClientId,
|
|
882
|
+
realm: realm || "main",
|
|
883
|
+
url: baseUrl ?? ""
|
|
884
|
+
},
|
|
885
|
+
children
|
|
886
|
+
}
|
|
887
|
+
) });
|
|
888
|
+
}
|