@multiplatform.one/keycloak 3.0.0 → 5.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/Authenticated.cjs +83 -0
- package/dist/cjs/Authenticated.js +10 -6
- package/dist/cjs/Authenticated.js.map +1 -1
- package/dist/cjs/Authenticated.native.js +9 -24
- package/dist/cjs/Authenticated.native.js.map +3 -3
- package/dist/cjs/Loading.cjs +39 -0
- package/dist/cjs/Loading.js +25 -0
- package/dist/cjs/Loading.js.map +6 -0
- package/dist/cjs/Loading.native.js +32 -0
- package/dist/cjs/Loading.native.js.map +6 -0
- package/dist/cjs/authConfig.cjs +29 -0
- package/dist/cjs/authConfig.js +0 -1
- package/dist/cjs/authConfig.js.map +1 -1
- package/dist/cjs/authConfig.native.js +1 -1
- package/dist/cjs/authConfig.native.js.map +2 -2
- package/dist/cjs/hooks/index.cjs +20 -0
- package/dist/cjs/hooks/index.js +1 -1
- package/dist/cjs/hooks/index.js.map +1 -1
- package/dist/cjs/hooks/index.native.js +3 -2
- package/dist/cjs/hooks/index.native.js.map +2 -2
- package/dist/cjs/hooks/useAuthConfig.cjs +30 -0
- package/dist/cjs/hooks/useAuthConfig.native.js +1 -0
- package/dist/cjs/hooks/useAuthConfig.native.js.map +2 -2
- package/dist/cjs/hooks/useTokensFromQuery/index.cjs +35 -0
- package/dist/cjs/hooks/useTokensFromQuery/index.js +7 -5
- package/dist/cjs/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/cjs/hooks/useTokensFromQuery/index.native.js +1 -0
- package/dist/cjs/hooks/useTokensFromQuery/index.native.js.map +2 -2
- package/dist/cjs/hooks/useTokensFromState.cjs +31 -0
- package/dist/cjs/hooks/useTokensFromState.js +5 -4
- package/dist/cjs/hooks/useTokensFromState.js.map +1 -1
- package/dist/cjs/hooks/useTokensFromState.native.js +7 -5
- package/dist/cjs/hooks/useTokensFromState.native.js.map +3 -3
- package/dist/cjs/index.cjs +24 -0
- package/dist/cjs/index.js +9 -9
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/index.native.js +12 -11
- package/dist/cjs/index.native.js.map +2 -2
- package/dist/cjs/keycloak/base.cjs +90 -0
- package/dist/cjs/keycloak/base.js +90 -0
- package/dist/cjs/keycloak/base.js.map +6 -0
- package/dist/cjs/keycloak/base.native.js +135 -0
- package/dist/cjs/keycloak/base.native.js.map +6 -0
- package/dist/cjs/keycloak/config.cjs +31 -0
- package/dist/cjs/keycloak/config.js +0 -1
- package/dist/cjs/keycloak/config.js.map +1 -1
- package/dist/cjs/keycloak/config.native.js +1 -1
- package/dist/cjs/keycloak/config.native.js.map +2 -2
- package/dist/cjs/keycloak/context.cjs +27 -0
- package/dist/cjs/keycloak/context.js +0 -1
- package/dist/cjs/keycloak/context.js.map +1 -1
- package/dist/cjs/keycloak/context.native.js +1 -1
- package/dist/cjs/keycloak/context.native.js.map +2 -2
- package/dist/cjs/keycloak/index.cjs +131 -0
- package/dist/cjs/keycloak/index.electron.cjs +30 -0
- package/dist/cjs/{session/session.js → keycloak/index.electron.js} +11 -16
- package/dist/cjs/keycloak/index.electron.js.map +6 -0
- package/dist/cjs/keycloak/index.electron.native.js +88 -0
- package/dist/cjs/keycloak/index.electron.native.js.map +6 -0
- package/dist/cjs/keycloak/index.js +86 -2
- package/dist/cjs/keycloak/index.js.map +2 -2
- package/dist/cjs/keycloak/index.native.js +87 -8
- package/dist/cjs/keycloak/index.native.js.map +3 -3
- package/dist/cjs/one.cjs +121 -0
- package/dist/cjs/{routes.js → one.js} +47 -62
- package/dist/cjs/one.js.map +6 -0
- package/dist/cjs/one.native.js +125 -0
- package/dist/cjs/one.native.js.map +6 -0
- package/dist/cjs/provider/AfterAuth.cjs +57 -0
- package/dist/cjs/provider/AfterAuth.js +22 -15
- package/dist/cjs/provider/AfterAuth.js.map +1 -1
- package/dist/cjs/provider/AfterAuth.native.js +22 -9
- package/dist/cjs/provider/AfterAuth.native.js.map +3 -3
- package/dist/cjs/provider/AuthProvider/index.cjs +223 -0
- package/dist/cjs/provider/AuthProvider/index.electron.cjs +223 -0
- package/dist/cjs/provider/AuthProvider/index.electron.js +243 -0
- package/dist/cjs/provider/AuthProvider/index.electron.js.map +6 -0
- package/dist/cjs/provider/AuthProvider/index.electron.native.js +300 -0
- package/dist/cjs/provider/AuthProvider/index.electron.native.js.map +6 -0
- package/dist/cjs/provider/AuthProvider/index.js +230 -5
- package/dist/cjs/provider/AuthProvider/index.js.map +3 -3
- package/dist/cjs/provider/AuthProvider/index.native.js +185 -7
- package/dist/cjs/provider/AuthProvider/index.native.js.map +3 -3
- package/dist/cjs/provider/AuthProvider/shared.cjs +36 -0
- package/dist/cjs/provider/AuthProvider/shared.js +30 -0
- package/dist/cjs/provider/AuthProvider/shared.js.map +6 -0
- package/dist/cjs/provider/AuthProvider/shared.native.js +40 -0
- package/dist/cjs/provider/AuthProvider/shared.native.js.map +6 -0
- package/dist/cjs/provider/KeycloakProvider.cjs +60 -0
- package/dist/cjs/provider/KeycloakProvider.js +8 -5
- package/dist/cjs/provider/KeycloakProvider.js.map +1 -1
- package/dist/cjs/provider/KeycloakProvider.native.js +6 -7
- package/dist/cjs/provider/KeycloakProvider.native.js.map +3 -3
- package/dist/cjs/provider/index.cjs +20 -0
- package/dist/cjs/provider/index.native.js +1 -0
- package/dist/cjs/provider/index.native.js.map +2 -2
- package/dist/cjs/session/index.cjs +36 -0
- package/dist/cjs/session/index.js +18 -3
- package/dist/cjs/session/index.js.map +2 -2
- package/dist/cjs/session/index.native.js +21 -7
- package/dist/cjs/session/index.native.js.map +3 -3
- package/dist/cjs/state.cjs +37 -0
- package/dist/cjs/state.js +10 -14
- package/dist/cjs/state.js.map +1 -1
- package/dist/cjs/state.native.js +21 -11
- package/dist/cjs/state.native.js.map +3 -3
- package/dist/cjs/token.cjs +36 -0
- package/dist/cjs/token.js.map +1 -1
- package/dist/cjs/token.native.js +2 -1
- package/dist/cjs/token.native.js.map +2 -2
- package/dist/cjs/types.cjs +16 -0
- package/dist/cjs/types.native.js +1 -0
- package/dist/cjs/types.native.js.map +2 -2
- package/dist/esm/Authenticated.js +11 -7
- package/dist/esm/Authenticated.js.map +1 -1
- package/dist/esm/Authenticated.mjs +7 -7
- package/dist/esm/Authenticated.mjs.map +1 -0
- package/dist/esm/Authenticated.native.js +10 -26
- package/dist/esm/Authenticated.native.js.map +3 -3
- package/dist/esm/Loading.js +11 -0
- package/dist/esm/Loading.js.map +6 -0
- package/dist/esm/Loading.mjs +16 -0
- package/dist/esm/Loading.mjs.map +1 -0
- package/dist/esm/Loading.native.js +13 -0
- package/dist/esm/Loading.native.js.map +6 -0
- package/dist/esm/authConfig.js +0 -1
- package/dist/esm/authConfig.js.map +1 -1
- package/dist/esm/authConfig.mjs +2 -3
- package/dist/esm/authConfig.mjs.map +1 -0
- package/dist/esm/authConfig.native.js +0 -1
- package/dist/esm/authConfig.native.js.map +2 -2
- package/dist/esm/hooks/index.js +1 -1
- package/dist/esm/hooks/index.mjs +2 -1
- package/dist/esm/hooks/index.mjs.map +1 -0
- package/dist/esm/hooks/index.native.js +1 -1
- package/dist/esm/hooks/index.native.js.map +1 -1
- package/dist/esm/hooks/useAuthConfig.mjs +2 -1
- package/dist/esm/hooks/useAuthConfig.mjs.map +1 -0
- package/dist/esm/hooks/useAuthConfig.native.js.map +1 -1
- package/dist/esm/hooks/useTokensFromQuery/index.js +8 -6
- package/dist/esm/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/esm/hooks/useTokensFromQuery/index.mjs +9 -11
- package/dist/esm/hooks/useTokensFromQuery/index.mjs.map +1 -0
- package/dist/esm/hooks/useTokensFromQuery/index.native.js.map +1 -1
- package/dist/esm/hooks/useTokensFromState.js +6 -5
- package/dist/esm/hooks/useTokensFromState.js.map +1 -1
- package/dist/esm/hooks/useTokensFromState.mjs +6 -5
- package/dist/esm/hooks/useTokensFromState.mjs.map +1 -0
- package/dist/esm/hooks/useTokensFromState.native.js +6 -5
- package/dist/esm/hooks/useTokensFromState.native.js.map +3 -3
- package/dist/esm/index.js +2 -2
- package/dist/esm/index.mjs +4 -3
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +2 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/keycloak/base.js +77 -0
- package/dist/esm/keycloak/base.js.map +6 -0
- package/dist/esm/keycloak/base.mjs +66 -0
- package/dist/esm/keycloak/base.mjs.map +1 -0
- package/dist/esm/keycloak/base.native.js +116 -0
- package/dist/esm/keycloak/base.native.js.map +6 -0
- package/dist/esm/keycloak/config.js +0 -1
- package/dist/esm/keycloak/config.js.map +1 -1
- package/dist/esm/keycloak/config.mjs +2 -3
- package/dist/esm/keycloak/config.mjs.map +1 -0
- package/dist/esm/keycloak/config.native.js +0 -1
- package/dist/esm/keycloak/config.native.js.map +2 -2
- package/dist/esm/keycloak/context.js +0 -1
- package/dist/esm/keycloak/context.js.map +1 -1
- package/dist/esm/keycloak/context.mjs +2 -3
- package/dist/esm/keycloak/context.mjs.map +1 -0
- package/dist/esm/keycloak/context.native.js +0 -1
- package/dist/esm/keycloak/context.native.js.map +2 -2
- package/dist/esm/keycloak/index.electron.js +9 -0
- package/dist/esm/keycloak/index.electron.js.map +6 -0
- package/dist/esm/keycloak/index.electron.mjs +6 -0
- package/dist/esm/keycloak/index.electron.mjs.map +1 -0
- package/dist/esm/keycloak/index.electron.native.js +65 -0
- package/dist/esm/keycloak/index.electron.native.js.map +6 -0
- package/dist/esm/keycloak/index.js +96 -1
- package/dist/esm/keycloak/index.js.map +1 -1
- package/dist/esm/keycloak/index.mjs +104 -1
- package/dist/esm/keycloak/index.mjs.map +1 -0
- package/dist/esm/keycloak/index.native.js +80 -2
- package/dist/esm/keycloak/index.native.js.map +3 -3
- package/dist/esm/one.js +96 -0
- package/dist/esm/one.js.map +6 -0
- package/dist/esm/one.mjs +87 -0
- package/dist/esm/one.mjs.map +1 -0
- package/dist/esm/one.native.js +98 -0
- package/dist/esm/one.native.js.map +6 -0
- package/dist/esm/provider/AfterAuth.js +21 -12
- package/dist/esm/provider/AfterAuth.js.map +1 -1
- package/dist/esm/provider/AfterAuth.mjs +19 -14
- package/dist/esm/provider/AfterAuth.mjs.map +1 -0
- package/dist/esm/provider/AfterAuth.native.js +32 -19
- package/dist/esm/provider/AfterAuth.native.js.map +3 -3
- package/dist/esm/provider/AuthProvider/index.electron.js +230 -0
- package/dist/esm/provider/AuthProvider/index.electron.js.map +6 -0
- package/dist/esm/provider/AuthProvider/index.electron.mjs +189 -0
- package/dist/esm/provider/AuthProvider/index.electron.mjs.map +1 -0
- package/dist/esm/provider/AuthProvider/index.electron.native.js +282 -0
- package/dist/esm/provider/AuthProvider/index.electron.native.js.map +6 -0
- package/dist/esm/provider/AuthProvider/index.js +227 -1
- package/dist/esm/provider/AuthProvider/index.js.map +3 -3
- package/dist/esm/provider/AuthProvider/index.mjs +189 -1
- package/dist/esm/provider/AuthProvider/index.mjs.map +1 -0
- package/dist/esm/provider/AuthProvider/index.native.js +185 -2
- package/dist/esm/provider/AuthProvider/index.native.js.map +3 -3
- package/dist/esm/provider/AuthProvider/shared.js +14 -0
- package/dist/esm/provider/AuthProvider/shared.js.map +6 -0
- package/dist/esm/provider/AuthProvider/shared.mjs +11 -0
- package/dist/esm/provider/AuthProvider/shared.mjs.map +1 -0
- package/dist/esm/provider/AuthProvider/shared.native.js +17 -0
- package/dist/esm/provider/AuthProvider/shared.native.js.map +6 -0
- package/dist/esm/provider/KeycloakProvider.js +9 -6
- package/dist/esm/provider/KeycloakProvider.js.map +1 -1
- package/dist/esm/provider/KeycloakProvider.mjs +10 -12
- package/dist/esm/provider/KeycloakProvider.mjs.map +1 -0
- package/dist/esm/provider/KeycloakProvider.native.js +6 -8
- package/dist/esm/provider/KeycloakProvider.native.js.map +3 -3
- package/dist/esm/provider/index.mjs +3 -2
- package/dist/esm/provider/index.mjs.map +1 -0
- package/dist/esm/provider/index.native.js.map +1 -1
- package/dist/esm/session/index.js +14 -1
- package/dist/esm/session/index.js.map +1 -1
- package/dist/esm/session/index.mjs +13 -1
- package/dist/esm/session/index.mjs.map +1 -0
- package/dist/esm/session/index.native.js +11 -2
- package/dist/esm/session/index.native.js.map +3 -3
- package/dist/esm/state.js +11 -15
- package/dist/esm/state.js.map +1 -1
- package/dist/esm/state.mjs +12 -15
- package/dist/esm/state.mjs.map +1 -0
- package/dist/esm/state.native.js +20 -12
- package/dist/esm/state.native.js.map +3 -3
- package/dist/esm/token.js.map +1 -1
- package/dist/esm/token.mjs +2 -1
- package/dist/esm/token.mjs.map +1 -0
- package/dist/esm/token.native.js +1 -1
- package/dist/esm/token.native.js.map +2 -2
- package/dist/esm/types.mjs +2 -0
- package/dist/esm/types.mjs.map +1 -0
- package/dist/jsx/Authenticated.js +11 -7
- package/dist/jsx/Authenticated.js.map +1 -1
- package/dist/jsx/Authenticated.mjs +7 -7
- package/dist/jsx/Authenticated.mjs.map +1 -0
- package/dist/jsx/Authenticated.native.js +9 -25
- package/dist/jsx/Authenticated.native.js.map +3 -3
- package/dist/jsx/Loading.js +11 -0
- package/dist/jsx/Loading.js.map +6 -0
- package/dist/jsx/Loading.mjs +16 -0
- package/dist/jsx/Loading.mjs.map +1 -0
- package/dist/jsx/Loading.native.js +13 -0
- package/dist/jsx/Loading.native.js.map +6 -0
- package/dist/jsx/authConfig.js +0 -1
- package/dist/jsx/authConfig.js.map +1 -1
- package/dist/jsx/authConfig.mjs +2 -3
- package/dist/jsx/authConfig.mjs.map +1 -0
- package/dist/jsx/authConfig.native.js +0 -1
- package/dist/jsx/authConfig.native.js.map +2 -2
- package/dist/jsx/hooks/index.js +1 -1
- package/dist/jsx/hooks/index.mjs +2 -1
- package/dist/jsx/hooks/index.mjs.map +1 -0
- package/dist/jsx/hooks/index.native.js +1 -1
- package/dist/jsx/hooks/index.native.js.map +1 -1
- package/dist/jsx/hooks/useAuthConfig.mjs +2 -1
- package/dist/jsx/hooks/useAuthConfig.mjs.map +1 -0
- package/dist/jsx/hooks/useAuthConfig.native.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromQuery/index.js +8 -6
- package/dist/jsx/hooks/useTokensFromQuery/index.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs +9 -11
- package/dist/jsx/hooks/useTokensFromQuery/index.mjs.map +1 -0
- package/dist/jsx/hooks/useTokensFromQuery/index.native.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromState.js +6 -5
- package/dist/jsx/hooks/useTokensFromState.js.map +1 -1
- package/dist/jsx/hooks/useTokensFromState.mjs +6 -5
- package/dist/jsx/hooks/useTokensFromState.mjs.map +1 -0
- package/dist/jsx/hooks/useTokensFromState.native.js +6 -5
- package/dist/jsx/hooks/useTokensFromState.native.js.map +3 -3
- package/dist/jsx/index.js +2 -2
- package/dist/jsx/index.mjs +4 -3
- package/dist/jsx/index.mjs.map +1 -0
- package/dist/jsx/index.native.js +2 -2
- package/dist/jsx/index.native.js.map +1 -1
- package/dist/jsx/keycloak/base.js +77 -0
- package/dist/jsx/keycloak/base.js.map +6 -0
- package/dist/jsx/keycloak/base.mjs +66 -0
- package/dist/jsx/keycloak/base.mjs.map +1 -0
- package/dist/jsx/keycloak/base.native.js +116 -0
- package/dist/jsx/keycloak/base.native.js.map +6 -0
- package/dist/jsx/keycloak/config.js +0 -1
- package/dist/jsx/keycloak/config.js.map +1 -1
- package/dist/jsx/keycloak/config.mjs +2 -3
- package/dist/jsx/keycloak/config.mjs.map +1 -0
- package/dist/jsx/keycloak/config.native.js +0 -1
- package/dist/jsx/keycloak/config.native.js.map +2 -2
- package/dist/jsx/keycloak/context.js +0 -1
- package/dist/jsx/keycloak/context.js.map +1 -1
- package/dist/jsx/keycloak/context.mjs +2 -3
- package/dist/jsx/keycloak/context.mjs.map +1 -0
- package/dist/jsx/keycloak/context.native.js +0 -1
- package/dist/jsx/keycloak/context.native.js.map +2 -2
- package/dist/jsx/keycloak/index.electron.js +9 -0
- package/dist/jsx/keycloak/index.electron.js.map +6 -0
- package/dist/jsx/keycloak/index.electron.mjs +6 -0
- package/dist/jsx/keycloak/index.electron.mjs.map +1 -0
- package/dist/jsx/keycloak/index.electron.native.js +65 -0
- package/dist/jsx/keycloak/index.electron.native.js.map +6 -0
- package/dist/jsx/keycloak/index.js +96 -1
- package/dist/jsx/keycloak/index.js.map +1 -1
- package/dist/jsx/keycloak/index.mjs +104 -1
- package/dist/jsx/keycloak/index.mjs.map +1 -0
- package/dist/jsx/keycloak/index.native.js +80 -2
- package/dist/jsx/keycloak/index.native.js.map +3 -3
- package/dist/jsx/one.js +96 -0
- package/dist/jsx/one.js.map +6 -0
- package/dist/jsx/one.mjs +87 -0
- package/dist/jsx/one.mjs.map +1 -0
- package/dist/jsx/one.native.js +98 -0
- package/dist/jsx/one.native.js.map +6 -0
- package/dist/jsx/provider/AfterAuth.js +21 -12
- package/dist/jsx/provider/AfterAuth.js.map +1 -1
- package/dist/jsx/provider/AfterAuth.mjs +19 -14
- package/dist/jsx/provider/AfterAuth.mjs.map +1 -0
- package/dist/jsx/provider/AfterAuth.native.js +20 -7
- package/dist/jsx/provider/AfterAuth.native.js.map +3 -3
- package/dist/jsx/provider/AuthProvider/index.electron.js +230 -0
- package/dist/jsx/provider/AuthProvider/index.electron.js.map +6 -0
- package/dist/jsx/provider/AuthProvider/index.electron.mjs +189 -0
- package/dist/jsx/provider/AuthProvider/index.electron.mjs.map +1 -0
- package/dist/jsx/provider/AuthProvider/index.electron.native.js +282 -0
- package/dist/jsx/provider/AuthProvider/index.electron.native.js.map +6 -0
- package/dist/jsx/provider/AuthProvider/index.js +227 -1
- package/dist/jsx/provider/AuthProvider/index.js.map +3 -3
- package/dist/jsx/provider/AuthProvider/index.mjs +189 -1
- package/dist/jsx/provider/AuthProvider/index.mjs.map +1 -0
- package/dist/jsx/provider/AuthProvider/index.native.js +185 -2
- package/dist/jsx/provider/AuthProvider/index.native.js.map +3 -3
- package/dist/jsx/provider/AuthProvider/shared.js +14 -0
- package/dist/jsx/provider/AuthProvider/shared.js.map +6 -0
- package/dist/jsx/provider/AuthProvider/shared.mjs +11 -0
- package/dist/jsx/provider/AuthProvider/shared.mjs.map +1 -0
- package/dist/jsx/provider/AuthProvider/shared.native.js +17 -0
- package/dist/jsx/provider/AuthProvider/shared.native.js.map +6 -0
- package/dist/jsx/provider/KeycloakProvider.js +9 -6
- package/dist/jsx/provider/KeycloakProvider.js.map +1 -1
- package/dist/jsx/provider/KeycloakProvider.mjs +10 -12
- package/dist/jsx/provider/KeycloakProvider.mjs.map +1 -0
- package/dist/jsx/provider/KeycloakProvider.native.js +6 -8
- package/dist/jsx/provider/KeycloakProvider.native.js.map +3 -3
- package/dist/jsx/provider/index.mjs +3 -2
- package/dist/jsx/provider/index.mjs.map +1 -0
- package/dist/jsx/provider/index.native.js.map +1 -1
- package/dist/jsx/session/index.js +14 -1
- package/dist/jsx/session/index.js.map +1 -1
- package/dist/jsx/session/index.mjs +13 -1
- package/dist/jsx/session/index.mjs.map +1 -0
- package/dist/jsx/session/index.native.js +11 -2
- package/dist/jsx/session/index.native.js.map +3 -3
- package/dist/jsx/state.js +11 -15
- package/dist/jsx/state.js.map +1 -1
- package/dist/jsx/state.mjs +12 -15
- package/dist/jsx/state.mjs.map +1 -0
- package/dist/jsx/state.native.js +20 -12
- package/dist/jsx/state.native.js.map +3 -3
- package/dist/jsx/token.js.map +1 -1
- package/dist/jsx/token.mjs +2 -1
- package/dist/jsx/token.mjs.map +1 -0
- package/dist/jsx/token.native.js +1 -1
- package/dist/jsx/token.native.js.map +2 -2
- package/dist/jsx/types.mjs +2 -0
- package/dist/jsx/types.mjs.map +1 -0
- package/package.json +27 -25
- package/src/@types/expoKeycloakAuth.d.ts +1 -1
- package/src/Authenticated.tsx +38 -19
- package/{routes/index.js → src/Loading.tsx} +19 -4
- package/src/authConfig.ts +2 -3
- package/src/hooks/index.ts +5 -5
- package/src/hooks/useAuthConfig.ts +2 -2
- package/src/hooks/useTokensFromQuery/index.ts +13 -8
- package/src/hooks/useTokensFromState.ts +6 -5
- package/src/index.ts +9 -9
- package/src/keycloak/base.ts +213 -0
- package/src/keycloak/config.ts +5 -7
- package/src/keycloak/context.ts +2 -4
- package/{routes/index.d.ts → src/keycloak/index.electron.ts} +9 -4
- package/src/keycloak/index.native.ts +46 -0
- package/src/keycloak/index.ts +150 -3
- package/src/one.ts +170 -0
- package/src/provider/AfterAuth.tsx +46 -25
- package/src/provider/AuthProvider/index.electron.tsx +410 -0
- package/src/provider/AuthProvider/index.native.tsx +298 -0
- package/src/provider/AuthProvider/index.tsx +417 -0
- package/src/provider/AuthProvider/shared.ts +65 -0
- package/src/provider/KeycloakProvider.tsx +21 -24
- package/src/provider/index.ts +5 -5
- package/src/session/{session.native.ts → index.native.ts} +6 -4
- package/src/session/index.ts +40 -2
- package/src/state.ts +12 -17
- package/src/token.ts +9 -6
- package/dist/cjs/keycloak/keycloak.js +0 -121
- package/dist/cjs/keycloak/keycloak.js.map +0 -6
- package/dist/cjs/keycloak/keycloak.native.js +0 -367
- package/dist/cjs/keycloak/keycloak.native.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/AuthProvider.js +0 -175
- package/dist/cjs/provider/AuthProvider/AuthProvider.js.map +0 -6
- package/dist/cjs/provider/AuthProvider/AuthProvider.native.js +0 -401
- package/dist/cjs/provider/AuthProvider/AuthProvider.native.js.map +0 -6
- package/dist/cjs/routes.js.map +0 -6
- package/dist/cjs/routes.native.js +0 -385
- package/dist/cjs/routes.native.js.map +0 -6
- package/dist/cjs/session/session.js.map +0 -6
- package/dist/cjs/session/session.native.js +0 -152
- package/dist/cjs/session/session.native.js.map +0 -6
- package/dist/esm/keycloak/keycloak.js +0 -112
- package/dist/esm/keycloak/keycloak.js.map +0 -6
- package/dist/esm/keycloak/keycloak.mjs +0 -108
- package/dist/esm/keycloak/keycloak.native.js +0 -350
- package/dist/esm/keycloak/keycloak.native.js.map +0 -6
- package/dist/esm/provider/AuthProvider/AuthProvider.js +0 -162
- package/dist/esm/provider/AuthProvider/AuthProvider.js.map +0 -6
- package/dist/esm/provider/AuthProvider/AuthProvider.mjs +0 -168
- package/dist/esm/provider/AuthProvider/AuthProvider.native.js +0 -388
- package/dist/esm/provider/AuthProvider/AuthProvider.native.js.map +0 -6
- package/dist/esm/routes.js +0 -119
- package/dist/esm/routes.js.map +0 -6
- package/dist/esm/routes.mjs +0 -109
- package/dist/esm/routes.native.js +0 -364
- package/dist/esm/routes.native.js.map +0 -6
- package/dist/esm/session/session.js +0 -15
- package/dist/esm/session/session.js.map +0 -6
- package/dist/esm/session/session.mjs +0 -12
- package/dist/esm/session/session.native.js +0 -131
- package/dist/esm/session/session.native.js.map +0 -6
- package/dist/jsx/keycloak/keycloak.js +0 -112
- package/dist/jsx/keycloak/keycloak.js.map +0 -6
- package/dist/jsx/keycloak/keycloak.mjs +0 -108
- package/dist/jsx/keycloak/keycloak.native.js +0 -350
- package/dist/jsx/keycloak/keycloak.native.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/AuthProvider.js +0 -162
- package/dist/jsx/provider/AuthProvider/AuthProvider.js.map +0 -6
- package/dist/jsx/provider/AuthProvider/AuthProvider.mjs +0 -168
- package/dist/jsx/provider/AuthProvider/AuthProvider.native.js +0 -388
- package/dist/jsx/provider/AuthProvider/AuthProvider.native.js.map +0 -6
- package/dist/jsx/routes.js +0 -119
- package/dist/jsx/routes.js.map +0 -6
- package/dist/jsx/routes.mjs +0 -109
- package/dist/jsx/routes.native.js +0 -364
- package/dist/jsx/routes.native.js.map +0 -6
- package/dist/jsx/session/session.js +0 -15
- package/dist/jsx/session/session.js.map +0 -6
- package/dist/jsx/session/session.mjs +0 -12
- package/dist/jsx/session/session.native.js +0 -131
- package/dist/jsx/session/session.native.js.map +0 -6
- package/src/keycloak/keycloak.native.ts +0 -182
- package/src/keycloak/keycloak.ts +0 -214
- package/src/provider/AuthProvider/AuthProvider.native.tsx +0 -194
- package/src/provider/AuthProvider/AuthProvider.tsx +0 -294
- package/src/provider/AuthProvider/index.ts +0 -22
- package/src/routes.ts +0 -196
- package/src/session/session.ts +0 -53
- package/types/Authenticated.d.ts +0 -9
- package/types/Authenticated.d.ts.map +0 -1
- package/types/authConfig.d.ts +0 -10
- package/types/authConfig.d.ts.map +0 -1
- package/types/hooks/index.d.ts +0 -4
- 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 -8
- package/types/index.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 -3
- package/types/keycloak/index.d.ts.map +0 -1
- package/types/keycloak/keycloak.d.ts +0 -42
- package/types/keycloak/keycloak.d.ts.map +0 -1
- package/types/keycloak/keycloak.native.d.ts +0 -36
- package/types/keycloak/keycloak.native.d.ts.map +0 -1
- package/types/provider/AfterAuth.d.ts +0 -6
- package/types/provider/AfterAuth.d.ts.map +0 -1
- package/types/provider/AuthProvider/AuthProvider.d.ts +0 -21
- package/types/provider/AuthProvider/AuthProvider.d.ts.map +0 -1
- package/types/provider/AuthProvider/AuthProvider.native.d.ts +0 -4
- package/types/provider/AuthProvider/AuthProvider.native.d.ts.map +0 -1
- package/types/provider/AuthProvider/index.d.ts +0 -2
- package/types/provider/AuthProvider/index.d.ts.map +0 -1
- package/types/provider/KeycloakProvider.d.ts +0 -13
- package/types/provider/KeycloakProvider.d.ts.map +0 -1
- package/types/provider/index.d.ts +0 -4
- package/types/provider/index.d.ts.map +0 -1
- package/types/routes.d.ts +0 -31
- package/types/routes.d.ts.map +0 -1
- package/types/session/index.d.ts +0 -2
- package/types/session/index.d.ts.map +0 -1
- package/types/session/session.d.ts +0 -16
- package/types/session/session.d.ts.map +0 -1
- package/types/session/session.native.d.ts +0 -5
- package/types/session/session.native.d.ts.map +0 -1
- package/types/state.d.ts +0 -11
- 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
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* File: /src/keycloak/keycloak.native.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
|
-
import type KeycloakClient from 'keycloak-js';
|
|
23
|
-
import type { AccessTokenParsed, TokenParsed } from '../token';
|
|
24
|
-
import type { KeycloakConfig } from 'keycloak-js';
|
|
25
|
-
import type { KeycloakLoginOptions, KeycloakLogoutOptions } from '../keycloak';
|
|
26
|
-
import type { KeycloakMock } from '../types';
|
|
27
|
-
import { KeycloakConfigContext } from '../keycloak/config';
|
|
28
|
-
import { KeycloakContext } from './context';
|
|
29
|
-
import { MultiPlatform } from 'multiplatform.one';
|
|
30
|
-
import { jwtDecode } from 'jwt-decode';
|
|
31
|
-
import { useContext } from 'react';
|
|
32
|
-
|
|
33
|
-
export class Keycloak {
|
|
34
|
-
token?: string;
|
|
35
|
-
idToken?: string;
|
|
36
|
-
refreshToken?: string;
|
|
37
|
-
|
|
38
|
-
private _idTokenParsed?: TokenParsed;
|
|
39
|
-
private _login?: (_options: KeycloakLoginOptions) => Promise<undefined>;
|
|
40
|
-
private _logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>;
|
|
41
|
-
private _refreshTokenParsed?: TokenParsed;
|
|
42
|
-
private _tokenParsed?: AccessTokenParsed;
|
|
43
|
-
private keycloakClient?: KeycloakClient;
|
|
44
|
-
private mock: KeycloakMock | undefined;
|
|
45
|
-
|
|
46
|
-
constructor(
|
|
47
|
-
public readonly config: KeycloakConfig,
|
|
48
|
-
input?: string | KeycloakClient | KeycloakMock,
|
|
49
|
-
idToken?: string,
|
|
50
|
-
refreshToken?: string,
|
|
51
|
-
login?: (_options: KeycloakLoginOptions) => Promise<undefined>,
|
|
52
|
-
logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>,
|
|
53
|
-
) {
|
|
54
|
-
if (typeof input === 'string') {
|
|
55
|
-
this.token = input;
|
|
56
|
-
this.idToken = idToken;
|
|
57
|
-
this.refreshToken = refreshToken;
|
|
58
|
-
} else if (typeof input === 'object') {
|
|
59
|
-
if (typeof (input as KeycloakClient).init === 'function') {
|
|
60
|
-
this.keycloakClient = input as KeycloakClient;
|
|
61
|
-
} else {
|
|
62
|
-
this.mock = input as KeycloakMock;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (this.token && !this._tokenParsed) this._tokenParsed = jwtDecode(this.token) as AccessTokenParsed;
|
|
66
|
-
if (this.idToken && !this._idTokenParsed) this._idTokenParsed = jwtDecode(this.idToken) as TokenParsed;
|
|
67
|
-
if (this.refreshToken && !this._refreshTokenParsed) {
|
|
68
|
-
this._refreshTokenParsed = jwtDecode(this.refreshToken) as TokenParsed;
|
|
69
|
-
}
|
|
70
|
-
this._login = login;
|
|
71
|
-
this._logout = logout;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
get tokenParsed() {
|
|
75
|
-
if (this.keycloakClient) return this.keycloakClient.tokenParsed as AccessTokenParsed;
|
|
76
|
-
return this._tokenParsed;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
get idTokenParsed() {
|
|
80
|
-
if (this.keycloakClient) return this.keycloakClient.idTokenParsed as TokenParsed;
|
|
81
|
-
return this._idTokenParsed;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
get refreshTokenParsed() {
|
|
85
|
-
if (this.keycloakClient) return this.keycloakClient.refreshTokenParsed as TokenParsed;
|
|
86
|
-
return this._refreshTokenParsed;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get clientId() {
|
|
90
|
-
if (this.keycloakClient) return this.keycloakClient.clientId;
|
|
91
|
-
return this.tokenParsed?.azp || this.config.clientId;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get email() {
|
|
95
|
-
if (this.keycloakClient) return this.keycloakClient.tokenParsed?.email;
|
|
96
|
-
if (this.mock) return this.mock.email;
|
|
97
|
-
return this.tokenParsed?.email;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
get realm() {
|
|
101
|
-
if (this.keycloakClient) return this.keycloakClient.realm;
|
|
102
|
-
return this.tokenParsed?.iss?.split('/').pop() || this.config.realm;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
get realmAccess() {
|
|
106
|
-
if (this.keycloakClient) return this.keycloakClient.realmAccess;
|
|
107
|
-
return this.tokenParsed?.realm_access;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
get resourceAccess() {
|
|
111
|
-
if (this.keycloakClient) return this.keycloakClient.resourceAccess;
|
|
112
|
-
return this.tokenParsed?.resource_access;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
get sessionId() {
|
|
116
|
-
if (this.keycloakClient) return this.keycloakClient.sessionId;
|
|
117
|
-
return this.tokenParsed?.session_state;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
get subject() {
|
|
121
|
-
if (this.keycloakClient) return this.keycloakClient.subject;
|
|
122
|
-
return this.tokenParsed?.sub;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get username() {
|
|
126
|
-
if (this.mock) return this.mock.username;
|
|
127
|
-
return this.tokenParsed?.preferred_username;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
async getUserInfo() {
|
|
131
|
-
if (!this.authenticated) return;
|
|
132
|
-
const response = await fetch(`${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`, {
|
|
133
|
-
method: 'GET',
|
|
134
|
-
headers: {
|
|
135
|
-
Authorization: 'Bearer ' + this.token,
|
|
136
|
-
Accept: 'application/json',
|
|
137
|
-
},
|
|
138
|
-
});
|
|
139
|
-
if (response.ok) return response.json();
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
async login(options: KeycloakLoginOptions = {}) {
|
|
143
|
-
this.idToken = undefined;
|
|
144
|
-
this.refreshToken = undefined;
|
|
145
|
-
this.token = undefined;
|
|
146
|
-
if (this.keycloakClient) {
|
|
147
|
-
await this.keycloakClient.login(options);
|
|
148
|
-
} else {
|
|
149
|
-
await this._login?.(options);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
async logout(options: KeycloakLogoutOptions = {}) {
|
|
154
|
-
this.idToken = undefined;
|
|
155
|
-
this.refreshToken = undefined;
|
|
156
|
-
this.token = undefined;
|
|
157
|
-
if (this.keycloakClient) {
|
|
158
|
-
await this.keycloakClient.logout(options);
|
|
159
|
-
} else {
|
|
160
|
-
await this._logout?.(options);
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
get authenticated() {
|
|
165
|
-
if (this.mock) return true;
|
|
166
|
-
if (this.keycloakClient) return !!this.keycloakClient.authenticated;
|
|
167
|
-
if (!this.tokenParsed?.exp || !this.idToken) return false;
|
|
168
|
-
return this.tokenParsed.exp > Date.now() / 1000;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export function useKeycloak() {
|
|
173
|
-
const keycloak = useContext(KeycloakContext);
|
|
174
|
-
const keycloakConfig = useContext(KeycloakConfigContext);
|
|
175
|
-
if (keycloak) return keycloak;
|
|
176
|
-
if (MultiPlatform.isStorybook) {
|
|
177
|
-
return new Keycloak(keycloakConfig, {
|
|
178
|
-
email: 'storybook@example.com',
|
|
179
|
-
username: 'storybook',
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
package/src/keycloak/keycloak.ts
DELETED
|
@@ -1,214 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* File: /src/keycloak/keycloak.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
|
-
import type KeycloakClient from 'keycloak-js';
|
|
23
|
-
import type { AccessTokenParsed, TokenParsed } from '../token';
|
|
24
|
-
import type { AuthRequestPromptOptions } from 'expo-auth-session';
|
|
25
|
-
import type { KeycloakMock } from '../types';
|
|
26
|
-
import type { Session } from '../session/session';
|
|
27
|
-
import { KeycloakConfigContext, type KeycloakConfig } from './config';
|
|
28
|
-
import { KeycloakContext } from './context';
|
|
29
|
-
import { MultiPlatform } from 'multiplatform.one';
|
|
30
|
-
import { useSession } from '../session/session';
|
|
31
|
-
import { jwtDecode } from 'jwt-decode';
|
|
32
|
-
import { signIn, signOut } from 'next-auth/react';
|
|
33
|
-
import { useAuthConfig } from '../hooks';
|
|
34
|
-
import { useContext } from 'react';
|
|
35
|
-
import type {
|
|
36
|
-
KeycloakLoginOptions as KeycloakJsLoginOptions,
|
|
37
|
-
KeycloakLogoutOptions as KeycloakJsLogoutOptions,
|
|
38
|
-
} from 'keycloak-js';
|
|
39
|
-
|
|
40
|
-
export type KeycloakLoginOptions = KeycloakJsLoginOptions & AuthRequestPromptOptions & { redirect?: boolean };
|
|
41
|
-
export type KeycloakLogoutOptions = KeycloakJsLogoutOptions;
|
|
42
|
-
|
|
43
|
-
export class Keycloak {
|
|
44
|
-
token?: string;
|
|
45
|
-
idToken?: string;
|
|
46
|
-
refreshToken?: string;
|
|
47
|
-
|
|
48
|
-
private _idTokenParsed?: TokenParsed;
|
|
49
|
-
private _login?: (_options: KeycloakLoginOptions) => Promise<undefined>;
|
|
50
|
-
private _logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>;
|
|
51
|
-
private _refreshTokenParsed?: TokenParsed;
|
|
52
|
-
private _tokenParsed?: AccessTokenParsed;
|
|
53
|
-
private keycloakClient?: KeycloakClient;
|
|
54
|
-
private mock: KeycloakMock | undefined;
|
|
55
|
-
|
|
56
|
-
constructor(
|
|
57
|
-
public readonly config: KeycloakConfig,
|
|
58
|
-
input?: string | KeycloakClient | KeycloakMock | Session,
|
|
59
|
-
idToken?: string,
|
|
60
|
-
refreshToken?: string,
|
|
61
|
-
login?: (_options: KeycloakLoginOptions) => Promise<undefined>,
|
|
62
|
-
logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>,
|
|
63
|
-
) {
|
|
64
|
-
if (typeof input === 'string') {
|
|
65
|
-
this.token = input;
|
|
66
|
-
this.idToken = idToken;
|
|
67
|
-
this.refreshToken = refreshToken;
|
|
68
|
-
} else if (typeof input === 'object') {
|
|
69
|
-
if (typeof (input as KeycloakClient).init === 'function') {
|
|
70
|
-
this.keycloakClient = input as KeycloakClient;
|
|
71
|
-
} else if ((input as Session).accessToken) {
|
|
72
|
-
const session = input as Session;
|
|
73
|
-
this.token = session.accessToken;
|
|
74
|
-
this.idToken = session.idToken;
|
|
75
|
-
this.refreshToken = session.refreshToken;
|
|
76
|
-
} else {
|
|
77
|
-
this.mock = input as KeycloakMock;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
if (this.token && !this._tokenParsed) this._tokenParsed = jwtDecode(this.token) as AccessTokenParsed;
|
|
81
|
-
if (this.idToken && !this._idTokenParsed) this._idTokenParsed = jwtDecode(this.idToken) as TokenParsed;
|
|
82
|
-
if (this.refreshToken && !this._refreshTokenParsed) {
|
|
83
|
-
this._refreshTokenParsed = jwtDecode(this.refreshToken) as TokenParsed;
|
|
84
|
-
}
|
|
85
|
-
this._login = login;
|
|
86
|
-
this._logout = logout;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
get tokenParsed() {
|
|
90
|
-
if (this.keycloakClient) return this.keycloakClient.tokenParsed as AccessTokenParsed;
|
|
91
|
-
return this._tokenParsed;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
get idTokenParsed() {
|
|
95
|
-
if (this.keycloakClient) return this.keycloakClient.idTokenParsed as TokenParsed;
|
|
96
|
-
return this._idTokenParsed;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
get refreshTokenParsed() {
|
|
100
|
-
if (this.keycloakClient) return this.keycloakClient.refreshTokenParsed as TokenParsed;
|
|
101
|
-
return this._refreshTokenParsed;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
get clientId() {
|
|
105
|
-
if (this.keycloakClient) return this.keycloakClient.clientId;
|
|
106
|
-
return this.tokenParsed?.azp || this.config.clientId;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
get email() {
|
|
110
|
-
if (this.keycloakClient) return this.keycloakClient.tokenParsed?.email;
|
|
111
|
-
if (this.mock) return this.mock.email;
|
|
112
|
-
return this.tokenParsed?.email;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
get realm() {
|
|
116
|
-
if (this.keycloakClient) return this.keycloakClient.realm;
|
|
117
|
-
return this.tokenParsed?.iss?.split('/').pop() || this.config.realm;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
get realmAccess() {
|
|
121
|
-
if (this.keycloakClient) return this.keycloakClient.realmAccess;
|
|
122
|
-
return this.tokenParsed?.realm_access;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
get resourceAccess() {
|
|
126
|
-
if (this.keycloakClient) return this.keycloakClient.resourceAccess;
|
|
127
|
-
return this.tokenParsed?.resource_access;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
get sessionId() {
|
|
131
|
-
if (this.keycloakClient) return this.keycloakClient.sessionId;
|
|
132
|
-
return this.tokenParsed?.session_state;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
get subject() {
|
|
136
|
-
if (this.keycloakClient) return this.keycloakClient.subject;
|
|
137
|
-
return this.tokenParsed?.sub;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
get username() {
|
|
141
|
-
if (this.mock) return this.mock.username;
|
|
142
|
-
return this.tokenParsed?.preferred_username;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
async getUserInfo() {
|
|
146
|
-
if (!this.authenticated) return;
|
|
147
|
-
const response = await fetch(`${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`, {
|
|
148
|
-
method: 'GET',
|
|
149
|
-
headers: {
|
|
150
|
-
Authorization: 'Bearer ' + this.token,
|
|
151
|
-
Accept: 'application/json',
|
|
152
|
-
},
|
|
153
|
-
});
|
|
154
|
-
if (response.ok) return response.json();
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
async login(options: KeycloakLoginOptions = {}) {
|
|
158
|
-
this.idToken = undefined;
|
|
159
|
-
this.refreshToken = undefined;
|
|
160
|
-
this.token = undefined;
|
|
161
|
-
if (this.keycloakClient) {
|
|
162
|
-
await this.keycloakClient.login(options);
|
|
163
|
-
} else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
|
|
164
|
-
await signIn('keycloak', {
|
|
165
|
-
callbackUrl: options.redirectUri,
|
|
166
|
-
redirect: options.redirect,
|
|
167
|
-
});
|
|
168
|
-
} else {
|
|
169
|
-
await this._login?.(options);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
async logout(options: KeycloakLogoutOptions = {}) {
|
|
174
|
-
this.idToken = undefined;
|
|
175
|
-
this.refreshToken = undefined;
|
|
176
|
-
this.token = undefined;
|
|
177
|
-
if (this.keycloakClient) {
|
|
178
|
-
await this.keycloakClient.logout(options);
|
|
179
|
-
} else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
|
|
180
|
-
await fetch('/api/auth/logout', { method: 'GET' });
|
|
181
|
-
await signOut({
|
|
182
|
-
callbackUrl: options.redirectUri,
|
|
183
|
-
});
|
|
184
|
-
} else {
|
|
185
|
-
await this._logout?.(options);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
get authenticated() {
|
|
190
|
-
if (this.mock) return true;
|
|
191
|
-
if (this.keycloakClient) return !!this.keycloakClient.authenticated;
|
|
192
|
-
if (!this.tokenParsed?.exp || !this.idToken) return false;
|
|
193
|
-
return this.tokenParsed.exp > Date.now() / 1000;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export function useKeycloak() {
|
|
198
|
-
const keycloak = useContext(KeycloakContext);
|
|
199
|
-
const keycloakConfig = useContext(KeycloakConfigContext);
|
|
200
|
-
const { disabled } = useAuthConfig();
|
|
201
|
-
if (disabled) return null;
|
|
202
|
-
if (keycloak) return keycloak;
|
|
203
|
-
const { session, status } = useSession();
|
|
204
|
-
if (MultiPlatform.isStorybook) {
|
|
205
|
-
return new Keycloak(keycloakConfig, {
|
|
206
|
-
email: 'storybook@example.com',
|
|
207
|
-
username: 'storybook',
|
|
208
|
-
});
|
|
209
|
-
} else if (status === 'unauthenticated') {
|
|
210
|
-
return new Keycloak(keycloakConfig);
|
|
211
|
-
} else if (status === 'authenticated' && session?.accessToken) {
|
|
212
|
-
return new Keycloak(keycloakConfig, session as Session);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* File: /src/provider/AuthProvider/AuthProvider.native.tsx
|
|
3
|
-
* Project: @multiplatform.one/keycloak
|
|
4
|
-
* File Created: 09-01-2024 11:29:20
|
|
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
|
-
import React, { useState, useEffect, useMemo, useCallback } from 'react';
|
|
23
|
-
import type { AuthProviderProps, Tokens } from './AuthProvider';
|
|
24
|
-
import type { KeycloakLoginOptions, KeycloakLogoutOptions } from '../../keycloak';
|
|
25
|
-
import { AfterAuth } from '../AfterAuth';
|
|
26
|
-
import { Keycloak, KeycloakConfigContext } from '../../keycloak';
|
|
27
|
-
import { KeycloakContext } from '../../keycloak/context';
|
|
28
|
-
import { makeRedirectUri, useAuthRequest, useAutoDiscovery, refreshAsync, exchangeCodeAsync } from 'expo-auth-session';
|
|
29
|
-
import { persist, useAuthState } from '../../state';
|
|
30
|
-
import { validOrRefreshableToken, isTokenExpired } from '../../token';
|
|
31
|
-
|
|
32
|
-
const REFRESH_THRESHOLD = 5;
|
|
33
|
-
|
|
34
|
-
export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
|
|
35
|
-
const [keycloak, setKeycloak] = useState<Keycloak>();
|
|
36
|
-
const authState = useAuthState();
|
|
37
|
-
const initialRefreshToken = useMemo(() => validOrRefreshableToken((persist && authState.refreshToken) || false), []);
|
|
38
|
-
const keycloakUrl = `${keycloakConfig?.url}/realms/${keycloakConfig?.realm}`;
|
|
39
|
-
const clientId = keycloakConfig.publicClientId || keycloakConfig?.clientId || '';
|
|
40
|
-
const discovery = useAutoDiscovery(keycloakUrl);
|
|
41
|
-
const redirectUri = makeRedirectUri();
|
|
42
|
-
const [tokens, setTokens] = useState<Tokens<false>>({
|
|
43
|
-
refreshToken: initialRefreshToken,
|
|
44
|
-
token: validOrRefreshableToken((persist && authState.token) || false, initialRefreshToken),
|
|
45
|
-
idToken: validOrRefreshableToken((persist && authState.idToken) || false, initialRefreshToken),
|
|
46
|
-
});
|
|
47
|
-
const scopes = useMemo(
|
|
48
|
-
() => [...new Set(['email', 'openid', 'profile', ...(keycloakConfig.scopes || [])])],
|
|
49
|
-
[keycloakConfig.scopes],
|
|
50
|
-
);
|
|
51
|
-
const [request, response, promptAsync] = useAuthRequest(
|
|
52
|
-
{
|
|
53
|
-
clientId,
|
|
54
|
-
redirectUri: redirectUri,
|
|
55
|
-
scopes,
|
|
56
|
-
},
|
|
57
|
-
discovery,
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
useEffect(() => {
|
|
61
|
-
if (!discovery || !response?.type || !request?.codeVerifier || !clientId) return;
|
|
62
|
-
(async () => {
|
|
63
|
-
if (response?.type === 'success' && request.codeVerifier && response.params.code) {
|
|
64
|
-
const tokenResponse = await exchangeCodeAsync(
|
|
65
|
-
{
|
|
66
|
-
clientId,
|
|
67
|
-
code: response.params.code,
|
|
68
|
-
redirectUri,
|
|
69
|
-
scopes,
|
|
70
|
-
extraParams: {
|
|
71
|
-
code_verifier: request.codeVerifier,
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
discovery,
|
|
75
|
-
);
|
|
76
|
-
if (tokenResponse) {
|
|
77
|
-
setTokens({
|
|
78
|
-
idToken: tokenResponse.idToken,
|
|
79
|
-
refreshToken: tokenResponse.refreshToken,
|
|
80
|
-
token: tokenResponse.accessToken,
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
})();
|
|
85
|
-
}, [
|
|
86
|
-
!discovery,
|
|
87
|
-
request?.codeVerifier,
|
|
88
|
-
response?.type === 'success' ? response?.params?.code : undefined,
|
|
89
|
-
clientId,
|
|
90
|
-
scopes,
|
|
91
|
-
redirectUri,
|
|
92
|
-
]);
|
|
93
|
-
|
|
94
|
-
const resetTokens = useCallback(() => {
|
|
95
|
-
authState.setIdToken('');
|
|
96
|
-
authState.setRefreshToken('');
|
|
97
|
-
authState.setToken('');
|
|
98
|
-
setTokens({
|
|
99
|
-
refreshToken: undefined,
|
|
100
|
-
token: undefined,
|
|
101
|
-
idToken: undefined,
|
|
102
|
-
});
|
|
103
|
-
}, []);
|
|
104
|
-
|
|
105
|
-
const refreshTokens = useCallback(async () => {
|
|
106
|
-
if (!discovery) return;
|
|
107
|
-
if (typeof tokens.refreshToken === 'string') {
|
|
108
|
-
if (!isTokenExpired(tokens.refreshToken)) {
|
|
109
|
-
const tokenResponse = await refreshAsync(
|
|
110
|
-
{
|
|
111
|
-
clientId,
|
|
112
|
-
refreshToken: tokens.refreshToken,
|
|
113
|
-
scopes,
|
|
114
|
-
},
|
|
115
|
-
discovery,
|
|
116
|
-
);
|
|
117
|
-
if (tokenResponse) {
|
|
118
|
-
setTokens({
|
|
119
|
-
idToken: tokenResponse.idToken,
|
|
120
|
-
refreshToken: tokenResponse.refreshToken,
|
|
121
|
-
token: tokenResponse.accessToken,
|
|
122
|
-
});
|
|
123
|
-
} else {
|
|
124
|
-
resetTokens();
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
resetTokens();
|
|
128
|
-
}
|
|
129
|
-
} else if (
|
|
130
|
-
authState.refreshToken &&
|
|
131
|
-
typeof authState.refreshToken === 'string' &&
|
|
132
|
-
isTokenExpired(authState.refreshToken)
|
|
133
|
-
) {
|
|
134
|
-
resetTokens();
|
|
135
|
-
}
|
|
136
|
-
}, [!discovery, tokens.refreshToken, clientId, scopes]);
|
|
137
|
-
|
|
138
|
-
useEffect(() => {
|
|
139
|
-
if (!discovery) return;
|
|
140
|
-
refreshTokens();
|
|
141
|
-
}, [!discovery]);
|
|
142
|
-
|
|
143
|
-
useEffect(() => {
|
|
144
|
-
if (!request) return;
|
|
145
|
-
let refreshHandle: NodeJS.Timeout;
|
|
146
|
-
(async () => {
|
|
147
|
-
if (tokens.token && isTokenExpired(tokens.token)) {
|
|
148
|
-
await refreshTokens();
|
|
149
|
-
} else {
|
|
150
|
-
const _keycloak = new Keycloak(
|
|
151
|
-
keycloakConfig,
|
|
152
|
-
tokens.token || undefined,
|
|
153
|
-
tokens.idToken || undefined,
|
|
154
|
-
tokens.refreshToken || undefined,
|
|
155
|
-
async (options: KeycloakLoginOptions) => {
|
|
156
|
-
await promptAsync(options);
|
|
157
|
-
},
|
|
158
|
-
async (_options: KeycloakLogoutOptions) => {
|
|
159
|
-
resetTokens();
|
|
160
|
-
},
|
|
161
|
-
);
|
|
162
|
-
if (_keycloak.tokenParsed?.exp) {
|
|
163
|
-
const timeout =
|
|
164
|
-
Math.max(
|
|
165
|
-
Math.min(_keycloak.tokenParsed.exp, _keycloak.refreshTokenParsed?.exp || 0) -
|
|
166
|
-
Math.floor(Date.now() / 1000) -
|
|
167
|
-
REFRESH_THRESHOLD,
|
|
168
|
-
REFRESH_THRESHOLD,
|
|
169
|
-
) * 1000;
|
|
170
|
-
if (timeout > 0) {
|
|
171
|
-
refreshHandle = setTimeout(() => {
|
|
172
|
-
refreshTokens();
|
|
173
|
-
}, timeout);
|
|
174
|
-
} else {
|
|
175
|
-
setTimeout(() => _keycloak.logout(), Math.max(0, timeout + REFRESH_THRESHOLD) * 1000);
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
setKeycloak(_keycloak);
|
|
180
|
-
}
|
|
181
|
-
})();
|
|
182
|
-
return () => {
|
|
183
|
-
if (refreshHandle) clearTimeout(refreshHandle);
|
|
184
|
-
};
|
|
185
|
-
}, [!request, tokens.token, tokens.idToken, tokens.refreshToken, refreshTokens]);
|
|
186
|
-
|
|
187
|
-
return (
|
|
188
|
-
<KeycloakConfigContext.Provider value={keycloakConfig}>
|
|
189
|
-
<KeycloakContext.Provider value={keycloak}>
|
|
190
|
-
<AfterAuth>{children}</AfterAuth>
|
|
191
|
-
</KeycloakContext.Provider>
|
|
192
|
-
</KeycloakConfigContext.Provider>
|
|
193
|
-
);
|
|
194
|
-
}
|