@multiplatform.one/keycloak 1.0.36 → 2.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.
Files changed (313) hide show
  1. package/dist/cjs/Authenticated.js +9 -4
  2. package/dist/cjs/Authenticated.js.map +1 -1
  3. package/dist/cjs/Authenticated.native.js +7 -22
  4. package/dist/cjs/Authenticated.native.js.map +2 -2
  5. package/dist/cjs/Loading.js +25 -0
  6. package/dist/cjs/Loading.js.map +6 -0
  7. package/dist/cjs/Loading.native.js +31 -0
  8. package/dist/cjs/Loading.native.js.map +6 -0
  9. package/dist/cjs/hooks/useTokensFromState.js +5 -4
  10. package/dist/cjs/hooks/useTokensFromState.js.map +1 -1
  11. package/dist/cjs/hooks/useTokensFromState.native.js +6 -5
  12. package/dist/cjs/hooks/useTokensFromState.native.js.map +2 -2
  13. package/dist/cjs/keycloak/context.js.map +1 -1
  14. package/dist/cjs/keycloak/context.native.js.map +1 -1
  15. package/dist/cjs/keycloak/keycloak.js +10 -7
  16. package/dist/cjs/keycloak/keycloak.js.map +1 -1
  17. package/dist/cjs/keycloak/keycloak.native.js +27 -209
  18. package/dist/cjs/keycloak/keycloak.native.js.map +2 -2
  19. package/dist/cjs/provider/AfterAuth.js +12 -7
  20. package/dist/cjs/provider/AfterAuth.js.map +1 -1
  21. package/dist/cjs/provider/AfterAuth.native.js +6 -4
  22. package/dist/cjs/provider/AfterAuth.native.js.map +2 -2
  23. package/dist/cjs/provider/AuthProvider/AuthProvider.js +59 -23
  24. package/dist/cjs/provider/AuthProvider/AuthProvider.js.map +1 -1
  25. package/dist/cjs/provider/AuthProvider/AuthProvider.native.js +80 -321
  26. package/dist/cjs/provider/AuthProvider/AuthProvider.native.js.map +2 -2
  27. package/dist/cjs/provider/KeycloakProvider.js +4 -1
  28. package/dist/cjs/provider/KeycloakProvider.js.map +1 -1
  29. package/dist/cjs/provider/KeycloakProvider.native.js +1 -1
  30. package/dist/cjs/provider/KeycloakProvider.native.js.map +1 -1
  31. package/dist/cjs/routes.js +11 -10
  32. package/dist/cjs/routes.js.map +1 -1
  33. package/dist/cjs/routes.native.js +89 -333
  34. package/dist/cjs/routes.native.js.map +2 -2
  35. package/dist/cjs/session/session.js.map +1 -1
  36. package/dist/cjs/session/session.native.js +2 -122
  37. package/dist/cjs/session/session.native.js.map +1 -1
  38. package/dist/cjs/state.js +10 -14
  39. package/dist/cjs/state.js.map +1 -1
  40. package/dist/cjs/state.native.js +20 -11
  41. package/dist/cjs/state.native.js.map +2 -2
  42. package/dist/cjs/token.js.map +1 -1
  43. package/dist/cjs/token.native.js +1 -1
  44. package/dist/cjs/token.native.js.map +1 -1
  45. package/dist/esm/Authenticated.js +11 -4
  46. package/dist/esm/Authenticated.js.map +1 -1
  47. package/dist/esm/Authenticated.mjs +7 -5
  48. package/dist/esm/Authenticated.mjs.map +1 -0
  49. package/dist/esm/Authenticated.native.js +26 -37
  50. package/dist/esm/Authenticated.native.js.map +1 -6
  51. package/dist/esm/Loading.js +11 -0
  52. package/dist/esm/Loading.js.map +6 -0
  53. package/dist/esm/Loading.mjs +16 -0
  54. package/dist/esm/Loading.mjs.map +1 -0
  55. package/dist/esm/Loading.native.js +17 -0
  56. package/dist/esm/Loading.native.js.map +1 -0
  57. package/dist/esm/authConfig.mjs +2 -1
  58. package/dist/esm/authConfig.mjs.map +1 -0
  59. package/dist/esm/authConfig.native.js +5 -6
  60. package/dist/esm/authConfig.native.js.map +1 -6
  61. package/dist/esm/hooks/index.mjs +3 -2
  62. package/dist/esm/hooks/index.mjs.map +1 -0
  63. package/dist/esm/hooks/index.native.js +3 -3
  64. package/dist/esm/hooks/index.native.js.map +1 -6
  65. package/dist/esm/hooks/useAuthConfig.mjs +2 -1
  66. package/dist/esm/hooks/useAuthConfig.mjs.map +1 -0
  67. package/dist/esm/hooks/useAuthConfig.native.js +3 -5
  68. package/dist/esm/hooks/useAuthConfig.native.js.map +1 -6
  69. package/dist/esm/hooks/useTokensFromQuery/index.mjs +2 -1
  70. package/dist/esm/hooks/useTokensFromQuery/index.mjs.map +1 -0
  71. package/dist/esm/hooks/useTokensFromQuery/index.native.js +2 -4
  72. package/dist/esm/hooks/useTokensFromQuery/index.native.js.map +1 -6
  73. package/dist/esm/hooks/useTokensFromState.js +6 -5
  74. package/dist/esm/hooks/useTokensFromState.js.map +1 -1
  75. package/dist/esm/hooks/useTokensFromState.mjs +6 -5
  76. package/dist/esm/hooks/useTokensFromState.mjs.map +1 -0
  77. package/dist/esm/hooks/useTokensFromState.native.js +7 -9
  78. package/dist/esm/hooks/useTokensFromState.native.js.map +1 -6
  79. package/dist/esm/index.mjs +6 -5
  80. package/dist/esm/index.mjs.map +1 -0
  81. package/dist/esm/index.native.js +4 -4
  82. package/dist/esm/index.native.js.map +1 -6
  83. package/dist/esm/keycloak/config.mjs +2 -1
  84. package/dist/esm/keycloak/config.mjs.map +1 -0
  85. package/dist/esm/keycloak/config.native.js +3 -4
  86. package/dist/esm/keycloak/config.native.js.map +1 -6
  87. package/dist/esm/keycloak/context.js.map +1 -1
  88. package/dist/esm/keycloak/context.mjs +2 -1
  89. package/dist/esm/keycloak/context.mjs.map +1 -0
  90. package/dist/esm/keycloak/context.native.js +3 -4
  91. package/dist/esm/keycloak/context.native.js.map +1 -6
  92. package/dist/esm/keycloak/index.mjs +2 -1
  93. package/dist/esm/keycloak/index.mjs.map +1 -0
  94. package/dist/esm/keycloak/index.native.js +3 -3
  95. package/dist/esm/keycloak/index.native.js.map +1 -6
  96. package/dist/esm/keycloak/keycloak.js +14 -11
  97. package/dist/esm/keycloak/keycloak.js.map +1 -1
  98. package/dist/esm/keycloak/keycloak.mjs +8 -7
  99. package/dist/esm/keycloak/keycloak.mjs.map +1 -0
  100. package/dist/esm/keycloak/keycloak.native.js +112 -317
  101. package/dist/esm/keycloak/keycloak.native.js.map +1 -6
  102. package/dist/esm/provider/AfterAuth.js +16 -8
  103. package/dist/esm/provider/AfterAuth.js.map +1 -1
  104. package/dist/esm/provider/AfterAuth.mjs +13 -8
  105. package/dist/esm/provider/AfterAuth.mjs.map +1 -0
  106. package/dist/esm/provider/AfterAuth.native.js +25 -30
  107. package/dist/esm/provider/AfterAuth.native.js.map +1 -6
  108. package/dist/esm/provider/AuthProvider/AuthProvider.js +56 -19
  109. package/dist/esm/provider/AuthProvider/AuthProvider.js.map +1 -1
  110. package/dist/esm/provider/AuthProvider/AuthProvider.mjs +21 -14
  111. package/dist/esm/provider/AuthProvider/AuthProvider.mjs.map +1 -0
  112. package/dist/esm/provider/AuthProvider/AuthProvider.native.js +104 -364
  113. package/dist/esm/provider/AuthProvider/AuthProvider.native.js.map +1 -6
  114. package/dist/esm/provider/AuthProvider/index.mjs +2 -1
  115. package/dist/esm/provider/AuthProvider/index.mjs.map +1 -0
  116. package/dist/esm/provider/AuthProvider/index.native.js +2 -2
  117. package/dist/esm/provider/AuthProvider/index.native.js.map +1 -6
  118. package/dist/esm/provider/KeycloakProvider.js +4 -1
  119. package/dist/esm/provider/KeycloakProvider.js.map +1 -1
  120. package/dist/esm/provider/KeycloakProvider.mjs +3 -2
  121. package/dist/esm/provider/KeycloakProvider.mjs.map +1 -0
  122. package/dist/esm/provider/KeycloakProvider.native.js +22 -17
  123. package/dist/esm/provider/KeycloakProvider.native.js.map +1 -6
  124. package/dist/esm/provider/index.mjs +3 -2
  125. package/dist/esm/provider/index.mjs.map +1 -0
  126. package/dist/esm/provider/index.native.js +3 -3
  127. package/dist/esm/provider/index.native.js.map +1 -6
  128. package/dist/esm/routes.js +11 -10
  129. package/dist/esm/routes.js.map +1 -1
  130. package/dist/esm/routes.mjs +12 -12
  131. package/dist/esm/routes.mjs.map +1 -0
  132. package/dist/esm/routes.native.js +98 -342
  133. package/dist/esm/routes.native.js.map +1 -6
  134. package/dist/esm/session/index.mjs +2 -1
  135. package/dist/esm/session/index.mjs.map +1 -0
  136. package/dist/esm/session/index.native.js +2 -2
  137. package/dist/esm/session/index.native.js.map +1 -6
  138. package/dist/esm/session/session.js.map +1 -1
  139. package/dist/esm/session/session.mjs +2 -1
  140. package/dist/esm/session/session.mjs.map +1 -0
  141. package/dist/esm/session/session.native.js +3 -126
  142. package/dist/esm/session/session.native.js.map +1 -6
  143. package/dist/esm/state.js +10 -14
  144. package/dist/esm/state.js.map +1 -1
  145. package/dist/esm/state.mjs +11 -14
  146. package/dist/esm/state.mjs.map +1 -0
  147. package/dist/esm/state.native.js +22 -15
  148. package/dist/esm/state.native.js.map +1 -6
  149. package/dist/esm/token.js.map +1 -1
  150. package/dist/esm/token.mjs +2 -1
  151. package/dist/esm/token.mjs.map +1 -0
  152. package/dist/esm/token.native.js +6 -8
  153. package/dist/esm/token.native.js.map +1 -6
  154. package/dist/esm/types.mjs +2 -0
  155. package/dist/esm/types.mjs.map +1 -0
  156. package/dist/esm/types.native.js +2 -1
  157. package/dist/esm/types.native.js.map +1 -6
  158. package/dist/jsx/Authenticated.js +11 -4
  159. package/dist/jsx/Authenticated.js.map +1 -1
  160. package/dist/jsx/Authenticated.mjs +7 -5
  161. package/dist/jsx/Authenticated.mjs.map +1 -0
  162. package/dist/jsx/Authenticated.native.js +7 -22
  163. package/dist/jsx/Authenticated.native.js.map +2 -2
  164. package/dist/jsx/Loading.js +11 -0
  165. package/dist/jsx/Loading.js.map +6 -0
  166. package/dist/jsx/Loading.mjs +16 -0
  167. package/dist/jsx/Loading.mjs.map +1 -0
  168. package/dist/jsx/Loading.native.js +13 -0
  169. package/dist/jsx/Loading.native.js.map +6 -0
  170. package/dist/jsx/authConfig.mjs +2 -1
  171. package/dist/jsx/authConfig.mjs.map +1 -0
  172. package/dist/jsx/hooks/index.mjs +3 -2
  173. package/dist/jsx/hooks/index.mjs.map +1 -0
  174. package/dist/jsx/hooks/useAuthConfig.mjs +2 -1
  175. package/dist/jsx/hooks/useAuthConfig.mjs.map +1 -0
  176. package/dist/jsx/hooks/useTokensFromQuery/index.mjs +2 -1
  177. package/dist/jsx/hooks/useTokensFromQuery/index.mjs.map +1 -0
  178. package/dist/jsx/hooks/useTokensFromState.js +6 -5
  179. package/dist/jsx/hooks/useTokensFromState.js.map +1 -1
  180. package/dist/jsx/hooks/useTokensFromState.mjs +6 -5
  181. package/dist/jsx/hooks/useTokensFromState.mjs.map +1 -0
  182. package/dist/jsx/hooks/useTokensFromState.native.js +6 -5
  183. package/dist/jsx/hooks/useTokensFromState.native.js.map +2 -2
  184. package/dist/jsx/index.mjs +6 -5
  185. package/dist/jsx/index.mjs.map +1 -0
  186. package/dist/jsx/keycloak/config.mjs +2 -1
  187. package/dist/jsx/keycloak/config.mjs.map +1 -0
  188. package/dist/jsx/keycloak/context.js.map +1 -1
  189. package/dist/jsx/keycloak/context.mjs +2 -1
  190. package/dist/jsx/keycloak/context.mjs.map +1 -0
  191. package/dist/jsx/keycloak/context.native.js.map +1 -1
  192. package/dist/jsx/keycloak/index.mjs +2 -1
  193. package/dist/jsx/keycloak/index.mjs.map +1 -0
  194. package/dist/jsx/keycloak/keycloak.js +14 -11
  195. package/dist/jsx/keycloak/keycloak.js.map +1 -1
  196. package/dist/jsx/keycloak/keycloak.mjs +8 -7
  197. package/dist/jsx/keycloak/keycloak.mjs.map +1 -0
  198. package/dist/jsx/keycloak/keycloak.native.js +29 -211
  199. package/dist/jsx/keycloak/keycloak.native.js.map +2 -2
  200. package/dist/jsx/provider/AfterAuth.js +16 -8
  201. package/dist/jsx/provider/AfterAuth.js.map +1 -1
  202. package/dist/jsx/provider/AfterAuth.mjs +13 -8
  203. package/dist/jsx/provider/AfterAuth.mjs.map +1 -0
  204. package/dist/jsx/provider/AfterAuth.native.js +7 -4
  205. package/dist/jsx/provider/AfterAuth.native.js.map +2 -2
  206. package/dist/jsx/provider/AuthProvider/AuthProvider.js +56 -19
  207. package/dist/jsx/provider/AuthProvider/AuthProvider.js.map +1 -1
  208. package/dist/jsx/provider/AuthProvider/AuthProvider.mjs +21 -14
  209. package/dist/jsx/provider/AuthProvider/AuthProvider.mjs.map +1 -0
  210. package/dist/jsx/provider/AuthProvider/AuthProvider.native.js +84 -323
  211. package/dist/jsx/provider/AuthProvider/AuthProvider.native.js.map +2 -2
  212. package/dist/jsx/provider/AuthProvider/index.mjs +2 -1
  213. package/dist/jsx/provider/AuthProvider/index.mjs.map +1 -0
  214. package/dist/jsx/provider/KeycloakProvider.js +4 -1
  215. package/dist/jsx/provider/KeycloakProvider.js.map +1 -1
  216. package/dist/jsx/provider/KeycloakProvider.mjs +3 -2
  217. package/dist/jsx/provider/KeycloakProvider.mjs.map +1 -0
  218. package/dist/jsx/provider/KeycloakProvider.native.js +1 -1
  219. package/dist/jsx/provider/KeycloakProvider.native.js.map +1 -1
  220. package/dist/jsx/provider/index.mjs +3 -2
  221. package/dist/jsx/provider/index.mjs.map +1 -0
  222. package/dist/jsx/routes.js +11 -10
  223. package/dist/jsx/routes.js.map +1 -1
  224. package/dist/jsx/routes.mjs +12 -12
  225. package/dist/jsx/routes.mjs.map +1 -0
  226. package/dist/jsx/routes.native.js +89 -332
  227. package/dist/jsx/routes.native.js.map +2 -2
  228. package/dist/jsx/session/index.mjs +2 -1
  229. package/dist/jsx/session/index.mjs.map +1 -0
  230. package/dist/jsx/session/session.js.map +1 -1
  231. package/dist/jsx/session/session.mjs +2 -1
  232. package/dist/jsx/session/session.mjs.map +1 -0
  233. package/dist/jsx/session/session.native.js +2 -122
  234. package/dist/jsx/session/session.native.js.map +1 -1
  235. package/dist/jsx/state.js +10 -14
  236. package/dist/jsx/state.js.map +1 -1
  237. package/dist/jsx/state.mjs +11 -14
  238. package/dist/jsx/state.mjs.map +1 -0
  239. package/dist/jsx/state.native.js +19 -11
  240. package/dist/jsx/state.native.js.map +2 -2
  241. package/dist/jsx/token.js.map +1 -1
  242. package/dist/jsx/token.mjs +2 -1
  243. package/dist/jsx/token.mjs.map +1 -0
  244. package/dist/jsx/token.native.js +1 -1
  245. package/dist/jsx/token.native.js.map +1 -1
  246. package/dist/jsx/types.mjs +2 -0
  247. package/dist/jsx/types.mjs.map +1 -0
  248. package/package.json +12 -15
  249. package/routes/index.d.ts +1 -1
  250. package/routes/index.js +1 -1
  251. package/src/@types/expoKeycloakAuth.d.ts +1 -1
  252. package/src/Authenticated.tsx +41 -15
  253. package/src/Loading.tsx +37 -0
  254. package/src/authConfig.ts +2 -2
  255. package/src/hooks/index.ts +3 -3
  256. package/src/hooks/useAuthConfig.ts +2 -2
  257. package/src/hooks/useTokensFromQuery/index.ts +4 -4
  258. package/src/hooks/useTokensFromState.ts +6 -5
  259. package/src/index.ts +7 -7
  260. package/src/keycloak/config.ts +6 -6
  261. package/src/keycloak/context.ts +3 -3
  262. package/src/keycloak/index.ts +2 -2
  263. package/src/keycloak/keycloak.native.ts +35 -27
  264. package/src/keycloak/keycloak.ts +48 -37
  265. package/src/provider/AfterAuth.tsx +33 -17
  266. package/src/provider/AuthProvider/AuthProvider.native.tsx +78 -29
  267. package/src/provider/AuthProvider/AuthProvider.tsx +143 -81
  268. package/src/provider/AuthProvider/index.ts +1 -1
  269. package/src/provider/KeycloakProvider.tsx +12 -9
  270. package/src/provider/index.ts +3 -3
  271. package/src/routes.ts +45 -35
  272. package/src/session/index.ts +1 -1
  273. package/src/session/session.native.ts +5 -3
  274. package/src/session/session.ts +14 -7
  275. package/src/state.ts +12 -16
  276. package/src/token.ts +9 -6
  277. package/types/Authenticated.d.ts +3 -3
  278. package/types/Authenticated.d.ts.map +1 -1
  279. package/types/Loading.d.ts +6 -0
  280. package/types/Loading.d.ts.map +1 -0
  281. package/types/hooks/index.d.ts +3 -3
  282. package/types/hooks/useTokensFromState.d.ts +1 -1
  283. package/types/hooks/useTokensFromState.d.ts.map +1 -1
  284. package/types/index.d.ts +7 -7
  285. package/types/keycloak/config.d.ts +1 -1
  286. package/types/keycloak/context.d.ts +1 -1
  287. package/types/keycloak/context.d.ts.map +1 -1
  288. package/types/keycloak/index.d.ts +2 -2
  289. package/types/keycloak/keycloak.d.ts +7 -7
  290. package/types/keycloak/keycloak.d.ts.map +1 -1
  291. package/types/keycloak/keycloak.native.d.ts +5 -5
  292. package/types/keycloak/keycloak.native.d.ts.map +1 -1
  293. package/types/provider/AfterAuth.d.ts +3 -3
  294. package/types/provider/AfterAuth.d.ts.map +1 -1
  295. package/types/provider/AuthProvider/AuthProvider.d.ts +8 -7
  296. package/types/provider/AuthProvider/AuthProvider.d.ts.map +1 -1
  297. package/types/provider/AuthProvider/AuthProvider.native.d.ts +3 -3
  298. package/types/provider/AuthProvider/AuthProvider.native.d.ts.map +1 -1
  299. package/types/provider/AuthProvider/index.d.ts +1 -1
  300. package/types/provider/KeycloakProvider.d.ts +4 -4
  301. package/types/provider/KeycloakProvider.d.ts.map +1 -1
  302. package/types/provider/index.d.ts +3 -3
  303. package/types/routes.d.ts +4 -4
  304. package/types/routes.d.ts.map +1 -1
  305. package/types/session/index.d.ts +1 -1
  306. package/types/session/session.d.ts +3 -3
  307. package/types/session/session.d.ts.map +1 -1
  308. package/types/session/session.native.d.ts +2 -2
  309. package/types/session/session.native.d.ts.map +1 -1
  310. package/types/state.d.ts +4 -6
  311. package/types/state.d.ts.map +1 -1
  312. package/types/token.d.ts +2 -2
  313. package/types/token.d.ts.map +1 -1
@@ -19,10 +19,10 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use client';
22
+ "use client";
23
23
 
24
- import type { KeycloakConfig as KeycloakJsConfig } from 'keycloak-js';
25
- import { createContext } from 'react';
24
+ import type { KeycloakConfig as KeycloakJsConfig } from "keycloak-js";
25
+ import { createContext } from "react";
26
26
 
27
27
  export interface KeycloakConfig extends KeycloakJsConfig {
28
28
  publicClientId?: string;
@@ -30,7 +30,7 @@ export interface KeycloakConfig extends KeycloakJsConfig {
30
30
  }
31
31
 
32
32
  export const KeycloakConfigContext = createContext<KeycloakConfig>({
33
- clientId: '',
34
- realm: '',
35
- url: '',
33
+ clientId: "",
34
+ realm: "",
35
+ url: "",
36
36
  });
@@ -19,9 +19,9 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use client';
22
+ "use client";
23
23
 
24
- import type { Keycloak } from './keycloak';
25
- import { createContext } from 'react';
24
+ import { createContext } from "react";
25
+ import type { Keycloak } from "./keycloak";
26
26
 
27
27
  export const KeycloakContext = createContext<Keycloak | undefined>(undefined);
@@ -19,5 +19,5 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- export * from './config';
23
- export * from './keycloak';
22
+ export * from "./config";
23
+ export * from "./keycloak";
@@ -19,16 +19,16 @@
19
19
  * limitations under the License.
20
20
  */
21
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';
22
+ import { jwtDecode } from "jwt-decode";
23
+ import type KeycloakClient from "keycloak-js";
24
+ import type { KeycloakConfig } from "keycloak-js";
25
+ import { MultiPlatform } from "multiplatform.one";
26
+ import { useContext } from "react";
27
+ import type { KeycloakLoginOptions, KeycloakLogoutOptions } from "../keycloak";
28
+ import { KeycloakConfigContext } from "../keycloak/config";
29
+ import type { AccessTokenParsed, TokenParsed } from "../token";
30
+ import type { KeycloakMock } from "../types";
31
+ import { KeycloakContext } from "./context";
32
32
 
33
33
  export class Keycloak {
34
34
  token?: string;
@@ -51,19 +51,21 @@ export class Keycloak {
51
51
  login?: (_options: KeycloakLoginOptions) => Promise<undefined>,
52
52
  logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>,
53
53
  ) {
54
- if (typeof input === 'string') {
54
+ if (typeof input === "string") {
55
55
  this.token = input;
56
56
  this.idToken = idToken;
57
57
  this.refreshToken = refreshToken;
58
- } else if (typeof input === 'object') {
59
- if (typeof (input as KeycloakClient).init === 'function') {
58
+ } else if (typeof input === "object") {
59
+ if (typeof (input as KeycloakClient).init === "function") {
60
60
  this.keycloakClient = input as KeycloakClient;
61
61
  } else {
62
62
  this.mock = input as KeycloakMock;
63
63
  }
64
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;
65
+ if (this.token && !this._tokenParsed)
66
+ this._tokenParsed = jwtDecode(this.token) as AccessTokenParsed;
67
+ if (this.idToken && !this._idTokenParsed)
68
+ this._idTokenParsed = jwtDecode(this.idToken) as TokenParsed;
67
69
  if (this.refreshToken && !this._refreshTokenParsed) {
68
70
  this._refreshTokenParsed = jwtDecode(this.refreshToken) as TokenParsed;
69
71
  }
@@ -72,17 +74,20 @@ export class Keycloak {
72
74
  }
73
75
 
74
76
  get tokenParsed() {
75
- if (this.keycloakClient) return this.keycloakClient.tokenParsed as AccessTokenParsed;
77
+ if (this.keycloakClient)
78
+ return this.keycloakClient.tokenParsed as AccessTokenParsed;
76
79
  return this._tokenParsed;
77
80
  }
78
81
 
79
82
  get idTokenParsed() {
80
- if (this.keycloakClient) return this.keycloakClient.idTokenParsed as TokenParsed;
83
+ if (this.keycloakClient)
84
+ return this.keycloakClient.idTokenParsed as TokenParsed;
81
85
  return this._idTokenParsed;
82
86
  }
83
87
 
84
88
  get refreshTokenParsed() {
85
- if (this.keycloakClient) return this.keycloakClient.refreshTokenParsed as TokenParsed;
89
+ if (this.keycloakClient)
90
+ return this.keycloakClient.refreshTokenParsed as TokenParsed;
86
91
  return this._refreshTokenParsed;
87
92
  }
88
93
 
@@ -99,7 +104,7 @@ export class Keycloak {
99
104
 
100
105
  get realm() {
101
106
  if (this.keycloakClient) return this.keycloakClient.realm;
102
- return this.tokenParsed?.iss?.split('/').pop() || this.config.realm;
107
+ return this.tokenParsed?.iss?.split("/").pop() || this.config.realm;
103
108
  }
104
109
 
105
110
  get realmAccess() {
@@ -129,13 +134,16 @@ export class Keycloak {
129
134
 
130
135
  async getUserInfo() {
131
136
  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
+ const response = await fetch(
138
+ `${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`,
139
+ {
140
+ method: "GET",
141
+ headers: {
142
+ Authorization: `Bearer ${this.token}`,
143
+ Accept: "application/json",
144
+ },
137
145
  },
138
- });
146
+ );
139
147
  if (response.ok) return response.json();
140
148
  }
141
149
 
@@ -175,8 +183,8 @@ export function useKeycloak() {
175
183
  if (keycloak) return keycloak;
176
184
  if (MultiPlatform.isStorybook) {
177
185
  return new Keycloak(keycloakConfig, {
178
- email: 'storybook@example.com',
179
- username: 'storybook',
186
+ email: "storybook@example.com",
187
+ username: "storybook",
180
188
  });
181
189
  }
182
190
  }
@@ -19,25 +19,26 @@
19
19
  * limitations under the License.
20
20
  */
21
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';
22
+ import type { AuthRequestPromptOptions } from "expo-auth-session";
23
+ import { jwtDecode } from "jwt-decode";
24
+ import type KeycloakClient from "keycloak-js";
35
25
  import type {
36
26
  KeycloakLoginOptions as KeycloakJsLoginOptions,
37
27
  KeycloakLogoutOptions as KeycloakJsLogoutOptions,
38
- } from 'keycloak-js';
39
-
40
- export type KeycloakLoginOptions = KeycloakJsLoginOptions & AuthRequestPromptOptions & { redirect?: boolean };
28
+ } from "keycloak-js";
29
+ import { MultiPlatform } from "multiplatform.one";
30
+ import { signIn, signOut } from "next-auth/react";
31
+ import { useContext } from "react";
32
+ import { useAuthConfig } from "../hooks";
33
+ import type { Session } from "../session/session";
34
+ import { useSession } from "../session/session";
35
+ import type { AccessTokenParsed, TokenParsed } from "../token";
36
+ import type { KeycloakMock } from "../types";
37
+ import { type KeycloakConfig, KeycloakConfigContext } from "./config";
38
+ import { KeycloakContext } from "./context";
39
+
40
+ export type KeycloakLoginOptions = KeycloakJsLoginOptions &
41
+ AuthRequestPromptOptions & { redirect?: boolean };
41
42
  export type KeycloakLogoutOptions = KeycloakJsLogoutOptions;
42
43
 
43
44
  export class Keycloak {
@@ -61,12 +62,12 @@ export class Keycloak {
61
62
  login?: (_options: KeycloakLoginOptions) => Promise<undefined>,
62
63
  logout?: (_options: KeycloakLogoutOptions) => Promise<undefined>,
63
64
  ) {
64
- if (typeof input === 'string') {
65
+ if (typeof input === "string") {
65
66
  this.token = input;
66
67
  this.idToken = idToken;
67
68
  this.refreshToken = refreshToken;
68
- } else if (typeof input === 'object') {
69
- if (typeof (input as KeycloakClient).init === 'function') {
69
+ } else if (typeof input === "object") {
70
+ if (typeof (input as KeycloakClient).init === "function") {
70
71
  this.keycloakClient = input as KeycloakClient;
71
72
  } else if ((input as Session).accessToken) {
72
73
  const session = input as Session;
@@ -77,8 +78,10 @@ export class Keycloak {
77
78
  this.mock = input as KeycloakMock;
78
79
  }
79
80
  }
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;
81
+ if (this.token && !this._tokenParsed)
82
+ this._tokenParsed = jwtDecode(this.token) as AccessTokenParsed;
83
+ if (this.idToken && !this._idTokenParsed)
84
+ this._idTokenParsed = jwtDecode(this.idToken) as TokenParsed;
82
85
  if (this.refreshToken && !this._refreshTokenParsed) {
83
86
  this._refreshTokenParsed = jwtDecode(this.refreshToken) as TokenParsed;
84
87
  }
@@ -87,17 +90,20 @@ export class Keycloak {
87
90
  }
88
91
 
89
92
  get tokenParsed() {
90
- if (this.keycloakClient) return this.keycloakClient.tokenParsed as AccessTokenParsed;
93
+ if (this.keycloakClient)
94
+ return this.keycloakClient.tokenParsed as AccessTokenParsed;
91
95
  return this._tokenParsed;
92
96
  }
93
97
 
94
98
  get idTokenParsed() {
95
- if (this.keycloakClient) return this.keycloakClient.idTokenParsed as TokenParsed;
99
+ if (this.keycloakClient)
100
+ return this.keycloakClient.idTokenParsed as TokenParsed;
96
101
  return this._idTokenParsed;
97
102
  }
98
103
 
99
104
  get refreshTokenParsed() {
100
- if (this.keycloakClient) return this.keycloakClient.refreshTokenParsed as TokenParsed;
105
+ if (this.keycloakClient)
106
+ return this.keycloakClient.refreshTokenParsed as TokenParsed;
101
107
  return this._refreshTokenParsed;
102
108
  }
103
109
 
@@ -114,7 +120,7 @@ export class Keycloak {
114
120
 
115
121
  get realm() {
116
122
  if (this.keycloakClient) return this.keycloakClient.realm;
117
- return this.tokenParsed?.iss?.split('/').pop() || this.config.realm;
123
+ return this.tokenParsed?.iss?.split("/").pop() || this.config.realm;
118
124
  }
119
125
 
120
126
  get realmAccess() {
@@ -144,13 +150,16 @@ export class Keycloak {
144
150
 
145
151
  async getUserInfo() {
146
152
  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',
153
+ const response = await fetch(
154
+ `${this.config.url}/realms/${this.config.realm}/protocol/openid-connect/userinfo`,
155
+ {
156
+ method: "GET",
157
+ headers: {
158
+ Authorization: `Bearer ${this.token}`,
159
+ Accept: "application/json",
160
+ },
152
161
  },
153
- });
162
+ );
154
163
  if (response.ok) return response.json();
155
164
  }
156
165
 
@@ -161,7 +170,7 @@ export class Keycloak {
161
170
  if (this.keycloakClient) {
162
171
  await this.keycloakClient.login(options);
163
172
  } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
164
- await signIn('keycloak', {
173
+ await signIn("keycloak", {
165
174
  callbackUrl: options.redirectUri,
166
175
  redirect: options.redirect,
167
176
  });
@@ -177,7 +186,7 @@ export class Keycloak {
177
186
  if (this.keycloakClient) {
178
187
  await this.keycloakClient.logout(options);
179
188
  } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
180
- await fetch('/api/auth/logout', { method: 'GET' });
189
+ await fetch("/api/auth/logout", { method: "GET" });
181
190
  await signOut({
182
191
  callbackUrl: options.redirectUri,
183
192
  });
@@ -203,12 +212,14 @@ export function useKeycloak() {
203
212
  const { session, status } = useSession();
204
213
  if (MultiPlatform.isStorybook) {
205
214
  return new Keycloak(keycloakConfig, {
206
- email: 'storybook@example.com',
207
- username: 'storybook',
215
+ email: "storybook@example.com",
216
+ username: "storybook",
208
217
  });
209
- } else if (status === 'unauthenticated') {
218
+ }
219
+ if (status === "unauthenticated") {
210
220
  return new Keycloak(keycloakConfig);
211
- } else if (status === 'authenticated' && session?.accessToken) {
221
+ }
222
+ if (status === "authenticated" && session?.accessToken) {
212
223
  return new Keycloak(keycloakConfig, session as Session);
213
224
  }
214
225
  }
@@ -19,46 +19,62 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- 'use client';
22
+ "use client";
23
23
 
24
- import React, { useEffect } from 'react';
25
- import type { PropsWithChildren } from 'react';
26
- import { useAuthConfig } from '../hooks';
27
- import { useAuthState, persist } from '../state';
28
- import { useKeycloak } from '../keycloak';
24
+ import React, {
25
+ type ComponentType,
26
+ type PropsWithChildren,
27
+ useEffect,
28
+ } from "react";
29
+ import { Loading } from "../Loading";
30
+ import { useAuthConfig } from "../hooks";
31
+ import { useKeycloak } from "../keycloak";
32
+ import { persist, useAuthStore } from "../state";
29
33
 
30
- export interface AfterAuthProps extends PropsWithChildren {}
34
+ export interface AfterAuthProps extends PropsWithChildren {
35
+ loadingComponent?: ComponentType;
36
+ }
31
37
 
32
38
  const logger = console;
33
39
 
34
- export function AfterAuth({ children }: AfterAuthProps) {
40
+ export function AfterAuth({ children, loadingComponent }: AfterAuthProps) {
35
41
  const authConfig = useAuthConfig();
36
- const authState = useAuthState();
42
+ const authStore = useAuthStore();
37
43
  const keycloak = useKeycloak();
44
+ if (!authStore) return <Loading loadingComponent={loadingComponent} />;
38
45
 
39
46
  useEffect(() => {
40
47
  if (!persist || !keycloak?.authenticated) return;
41
48
  if (keycloak.token) {
42
- authState.setToken(keycloak.token);
43
- if (keycloak.idToken) authState.setIdToken(keycloak.idToken);
44
- if (keycloak.refreshToken) authState.setRefreshToken(keycloak.refreshToken);
49
+ authStore.token = keycloak.token;
50
+ if (keycloak.idToken) authStore.idToken = keycloak.idToken;
51
+ if (keycloak.refreshToken) authStore.refreshToken = keycloak.refreshToken;
45
52
  }
46
- }, [keycloak?.authenticated, keycloak?.token, keycloak?.idToken, keycloak?.refreshToken]);
53
+ }, [
54
+ keycloak?.authenticated,
55
+ keycloak?.token,
56
+ keycloak?.idToken,
57
+ keycloak?.refreshToken,
58
+ ]);
47
59
 
48
60
  useEffect(() => {
49
- if (authConfig.debug && keycloak?.token) logger.debug('token', keycloak.token);
61
+ if (authConfig.debug && keycloak?.token)
62
+ logger.debug("token", keycloak.token);
50
63
  }, [keycloak?.token]);
51
64
 
52
65
  useEffect(() => {
53
- if (authConfig.debug && keycloak?.idToken) logger.debug('idToken', keycloak.idToken);
66
+ if (authConfig.debug && keycloak?.idToken)
67
+ logger.debug("idToken", keycloak.idToken);
54
68
  }, [keycloak?.idToken]);
55
69
 
56
70
  useEffect(() => {
57
- if (authConfig.debug && keycloak?.refreshToken) logger.debug('refreshToken', keycloak.refreshToken);
71
+ if (authConfig.debug && keycloak?.refreshToken)
72
+ logger.debug("refreshToken", keycloak.refreshToken);
58
73
  }, [keycloak?.refreshToken]);
59
74
 
60
75
  useEffect(() => {
61
- if (authConfig.debug && keycloak?.authenticated) logger.debug('authenticated', keycloak.authenticated);
76
+ if (authConfig.debug && keycloak?.authenticated)
77
+ logger.debug("authenticated", keycloak.authenticated);
62
78
  }, [keycloak?.authenticated]);
63
79
 
64
80
  return <>{children}</>;
@@ -19,33 +19,65 @@
19
19
  * limitations under the License.
20
20
  */
21
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';
22
+ import {
23
+ exchangeCodeAsync,
24
+ makeRedirectUri,
25
+ refreshAsync,
26
+ useAuthRequest,
27
+ useAutoDiscovery,
28
+ } from "expo-auth-session";
29
+ import React, { useState, useEffect, useMemo, useCallback } from "react";
30
+ import { Loading } from "../../Loading";
31
+ import { Keycloak, KeycloakConfigContext } from "../../keycloak";
32
+ import type {
33
+ KeycloakLoginOptions,
34
+ KeycloakLogoutOptions,
35
+ } from "../../keycloak";
36
+ import { KeycloakContext } from "../../keycloak/context";
37
+ import { persist, useAuthStore } from "../../state";
38
+ import { isTokenExpired, validOrRefreshableToken } from "../../token";
39
+ import { AfterAuth } from "../AfterAuth";
40
+ import type { AuthProviderProps, Tokens } from "./AuthProvider";
31
41
 
32
42
  const REFRESH_THRESHOLD = 5;
33
43
 
34
- export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
44
+ export function AuthProvider({
45
+ children,
46
+ keycloakConfig,
47
+ loadingComponent,
48
+ }: AuthProviderProps) {
35
49
  const [keycloak, setKeycloak] = useState<Keycloak>();
36
- const authState = useAuthState();
37
- const initialRefreshToken = useMemo(() => validOrRefreshableToken((persist && authState.refreshToken) || false), []);
50
+ const authStore = useAuthStore();
51
+ if (!authStore) return <Loading loadingComponent={loadingComponent} />;
52
+ const initialRefreshToken = useMemo(
53
+ () => validOrRefreshableToken((persist && authStore.refreshToken) || false),
54
+ [],
55
+ );
38
56
  const keycloakUrl = `${keycloakConfig?.url}/realms/${keycloakConfig?.realm}`;
39
- const clientId = keycloakConfig.publicClientId || keycloakConfig?.clientId || '';
57
+ const clientId =
58
+ keycloakConfig.publicClientId || keycloakConfig?.clientId || "";
40
59
  const discovery = useAutoDiscovery(keycloakUrl);
41
60
  const redirectUri = makeRedirectUri();
42
61
  const [tokens, setTokens] = useState<Tokens<false>>({
43
62
  refreshToken: initialRefreshToken,
44
- token: validOrRefreshableToken((persist && authState.token) || false, initialRefreshToken),
45
- idToken: validOrRefreshableToken((persist && authState.idToken) || false, initialRefreshToken),
63
+ token: validOrRefreshableToken(
64
+ (persist && authStore.token) || false,
65
+ initialRefreshToken,
66
+ ),
67
+ idToken: validOrRefreshableToken(
68
+ (persist && authStore.idToken) || false,
69
+ initialRefreshToken,
70
+ ),
46
71
  });
47
72
  const scopes = useMemo(
48
- () => [...new Set(['email', 'openid', 'profile', ...(keycloakConfig.scopes || [])])],
73
+ () => [
74
+ ...new Set([
75
+ "email",
76
+ "openid",
77
+ "profile",
78
+ ...(keycloakConfig.scopes || []),
79
+ ]),
80
+ ],
49
81
  [keycloakConfig.scopes],
50
82
  );
51
83
  const [request, response, promptAsync] = useAuthRequest(
@@ -58,9 +90,14 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
58
90
  );
59
91
 
60
92
  useEffect(() => {
61
- if (!discovery || !response?.type || !request?.codeVerifier || !clientId) return;
93
+ if (!discovery || !response?.type || !request?.codeVerifier || !clientId)
94
+ return;
62
95
  (async () => {
63
- if (response?.type === 'success' && request.codeVerifier && response.params.code) {
96
+ if (
97
+ response?.type === "success" &&
98
+ request.codeVerifier &&
99
+ response.params.code
100
+ ) {
64
101
  const tokenResponse = await exchangeCodeAsync(
65
102
  {
66
103
  clientId,
@@ -85,16 +122,16 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
85
122
  }, [
86
123
  !discovery,
87
124
  request?.codeVerifier,
88
- response?.type === 'success' ? response?.params?.code : undefined,
125
+ response?.type === "success" ? response?.params?.code : undefined,
89
126
  clientId,
90
127
  scopes,
91
128
  redirectUri,
92
129
  ]);
93
130
 
94
131
  const resetTokens = useCallback(() => {
95
- authState.setIdToken('');
96
- authState.setRefreshToken('');
97
- authState.setToken('');
132
+ authStore.idToken = "";
133
+ authStore.refreshToken = "";
134
+ authStore.token = "";
98
135
  setTokens({
99
136
  refreshToken: undefined,
100
137
  token: undefined,
@@ -104,7 +141,7 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
104
141
 
105
142
  const refreshTokens = useCallback(async () => {
106
143
  if (!discovery) return;
107
- if (typeof tokens.refreshToken === 'string') {
144
+ if (typeof tokens.refreshToken === "string") {
108
145
  if (!isTokenExpired(tokens.refreshToken)) {
109
146
  const tokenResponse = await refreshAsync(
110
147
  {
@@ -127,9 +164,9 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
127
164
  resetTokens();
128
165
  }
129
166
  } else if (
130
- authState.refreshToken &&
131
- typeof authState.refreshToken === 'string' &&
132
- isTokenExpired(authState.refreshToken)
167
+ authStore.refreshToken &&
168
+ typeof authStore.refreshToken === "string" &&
169
+ isTokenExpired(authStore.refreshToken)
133
170
  ) {
134
171
  resetTokens();
135
172
  }
@@ -162,7 +199,10 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
162
199
  if (_keycloak.tokenParsed?.exp) {
163
200
  const timeout =
164
201
  Math.max(
165
- Math.min(_keycloak.tokenParsed.exp, _keycloak.refreshTokenParsed?.exp || 0) -
202
+ Math.min(
203
+ _keycloak.tokenParsed.exp,
204
+ _keycloak.refreshTokenParsed?.exp || 0,
205
+ ) -
166
206
  Math.floor(Date.now() / 1000) -
167
207
  REFRESH_THRESHOLD,
168
208
  REFRESH_THRESHOLD,
@@ -172,7 +212,10 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
172
212
  refreshTokens();
173
213
  }, timeout);
174
214
  } else {
175
- setTimeout(() => _keycloak.logout(), Math.max(0, timeout + REFRESH_THRESHOLD) * 1000);
215
+ setTimeout(
216
+ () => _keycloak.logout(),
217
+ Math.max(0, timeout + REFRESH_THRESHOLD) * 1000,
218
+ );
176
219
  return;
177
220
  }
178
221
  }
@@ -182,7 +225,13 @@ export function AuthProvider({ children, keycloakConfig }: AuthProviderProps) {
182
225
  return () => {
183
226
  if (refreshHandle) clearTimeout(refreshHandle);
184
227
  };
185
- }, [!request, tokens.token, tokens.idToken, tokens.refreshToken, refreshTokens]);
228
+ }, [
229
+ !request,
230
+ tokens.token,
231
+ tokens.idToken,
232
+ tokens.refreshToken,
233
+ refreshTokens,
234
+ ]);
186
235
 
187
236
  return (
188
237
  <KeycloakConfigContext.Provider value={keycloakConfig}>