@multiplatform.one/keycloak 0.0.1 → 0.0.3

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 (116) hide show
  1. package/esm/Authenticated.js +8 -19
  2. package/esm/Authenticated.js.map +1 -1
  3. package/esm/authConfig.js +2 -2
  4. package/esm/authConfig.js.map +1 -1
  5. package/esm/expo/ExpoKeycloakContext.js +28 -0
  6. package/esm/expo/ExpoKeycloakContext.js.map +1 -0
  7. package/esm/expo/ExpoKeycloakProvider.js +113 -0
  8. package/esm/expo/ExpoKeycloakProvider.js.map +1 -0
  9. package/esm/expo/KeycloakContext.js +28 -0
  10. package/esm/expo/KeycloakContext.js.map +1 -0
  11. package/esm/expo/KeycloakProvider.js +142 -0
  12. package/esm/expo/KeycloakProvider.js.map +1 -0
  13. package/esm/expo/const.js +42 -0
  14. package/esm/expo/const.js.map +1 -0
  15. package/esm/expo/helpers.js +56 -0
  16. package/esm/expo/helpers.js.map +1 -0
  17. package/esm/expo/index.js +28 -0
  18. package/esm/expo/index.js.map +1 -0
  19. package/esm/expo/useExpoKeycloak.js +44 -0
  20. package/esm/expo/useExpoKeycloak.js.map +1 -0
  21. package/esm/expo/useTokenStorage.js +153 -0
  22. package/esm/expo/useTokenStorage.js.map +1 -0
  23. package/esm/hooks/useCurrentRouteName.js +2 -3
  24. package/esm/hooks/useCurrentRouteName.js.map +1 -1
  25. package/esm/hooks/useKeycloak/index.js +1 -1
  26. package/esm/hooks/useKeycloak/index.js.map +1 -1
  27. package/esm/hooks/useKeycloak/useKeycloak.js +17 -24
  28. package/esm/hooks/useKeycloak/useKeycloak.js.map +1 -1
  29. package/esm/hooks/useKeycloak/useKeycloak.native.js +60 -19
  30. package/esm/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
  31. package/esm/hooks/useLogin.js +12 -30
  32. package/esm/hooks/useLogin.js.map +1 -1
  33. package/esm/provider/afterAuth.js +21 -39
  34. package/esm/provider/afterAuth.js.map +1 -1
  35. package/esm/provider/index.js +11 -28
  36. package/esm/provider/index.js.map +1 -1
  37. package/esm/provider/keycloakProvider.js +55 -100
  38. package/esm/provider/keycloakProvider.js.map +1 -1
  39. package/esm/provider/keycloakProvider.native.js +12 -11
  40. package/esm/provider/keycloakProvider.native.js.map +1 -1
  41. package/esm/state/index.js +2 -2
  42. package/esm/state/index.js.map +1 -1
  43. package/lib/Authenticated.js +38 -26
  44. package/lib/Authenticated.js.map +1 -1
  45. package/lib/authConfig.js +2 -4
  46. package/lib/authConfig.js.map +1 -1
  47. package/lib/expo/ExpoKeycloakContext.d.ts +32 -0
  48. package/lib/expo/ExpoKeycloakContext.js +47 -0
  49. package/lib/expo/ExpoKeycloakContext.js.map +1 -0
  50. package/lib/expo/ExpoKeycloakProvider.d.ts +37 -0
  51. package/lib/expo/ExpoKeycloakProvider.js +130 -0
  52. package/lib/expo/ExpoKeycloakProvider.js.map +1 -0
  53. package/lib/expo/KeycloakContext.d.ts +32 -0
  54. package/lib/expo/KeycloakContext.js +49 -0
  55. package/lib/expo/KeycloakContext.js.map +1 -0
  56. package/lib/expo/KeycloakProvider.d.ts +37 -0
  57. package/lib/expo/KeycloakProvider.js +138 -0
  58. package/lib/expo/KeycloakProvider.js.map +1 -0
  59. package/lib/expo/const.d.ts +33 -0
  60. package/lib/expo/const.js +66 -0
  61. package/lib/expo/const.js.map +1 -0
  62. package/lib/expo/helpers.d.ts +41 -0
  63. package/lib/expo/helpers.js +77 -0
  64. package/lib/expo/helpers.js.map +1 -0
  65. package/lib/expo/index.d.ts +26 -0
  66. package/lib/expo/index.js +50 -0
  67. package/lib/expo/index.js.map +1 -0
  68. package/lib/expo/useExpoKeycloak.d.ts +31 -0
  69. package/lib/expo/useExpoKeycloak.js +62 -0
  70. package/lib/expo/useExpoKeycloak.js.map +1 -0
  71. package/lib/expo/useTokenStorage.d.ts +36 -0
  72. package/lib/expo/useTokenStorage.js +166 -0
  73. package/lib/expo/useTokenStorage.js.map +1 -0
  74. package/lib/hooks/index.js +3 -9
  75. package/lib/hooks/index.js.map +1 -1
  76. package/lib/hooks/useAuthConfig.js +0 -2
  77. package/lib/hooks/useAuthConfig.js.map +1 -1
  78. package/lib/hooks/useCurrentRouteName.js +6 -8
  79. package/lib/hooks/useCurrentRouteName.js.map +1 -1
  80. package/lib/hooks/useKeycloak/index.d.ts +7 -4
  81. package/lib/hooks/useKeycloak/index.js +1 -7
  82. package/lib/hooks/useKeycloak/index.js.map +1 -1
  83. package/lib/hooks/useKeycloak/useKeycloak.js +45 -30
  84. package/lib/hooks/useKeycloak/useKeycloak.js.map +1 -1
  85. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +13 -3
  86. package/lib/hooks/useKeycloak/useKeycloak.native.js +61 -25
  87. package/lib/hooks/useKeycloak/useKeycloak.native.js.map +1 -1
  88. package/lib/hooks/useLogin.js +16 -25
  89. package/lib/hooks/useLogin.js.map +1 -1
  90. package/lib/index.js +4 -10
  91. package/lib/index.js.map +1 -1
  92. package/lib/provider/afterAuth.js +52 -52
  93. package/lib/provider/afterAuth.js.map +1 -1
  94. package/lib/provider/index.js +44 -43
  95. package/lib/provider/index.js.map +1 -1
  96. package/lib/provider/keycloakProvider.js +93 -114
  97. package/lib/provider/keycloakProvider.js.map +1 -1
  98. package/lib/provider/keycloakProvider.native.js +39 -15
  99. package/lib/provider/keycloakProvider.native.js.map +1 -1
  100. package/lib/state/index.js +3 -5
  101. package/lib/state/index.js.map +1 -1
  102. package/lib/tsconfig.build.tsbuildinfo +1 -1
  103. package/lib/types.js +2 -4
  104. package/lib/types.js.map +1 -1
  105. package/package.json +5 -4
  106. package/src/expo/ExpoKeycloakContext.ts +41 -0
  107. package/src/expo/ExpoKeycloakProvider.tsx +139 -0
  108. package/src/expo/NOTES +1 -0
  109. package/src/expo/const.ts +42 -0
  110. package/src/expo/helpers.ts +74 -0
  111. package/src/{@types/expoKeycloakAuth.d.ts → expo/index.ts} +6 -7
  112. package/src/expo/useExpoKeycloak.ts +44 -0
  113. package/src/expo/useTokenStorage.ts +168 -0
  114. package/src/hooks/useKeycloak/index.ts +11 -4
  115. package/src/hooks/useKeycloak/useKeycloak.native.ts +72 -8
  116. package/src/provider/keycloakProvider.native.tsx +8 -4
@@ -1,6 +1,3 @@
1
- import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
2
- var _this = this;
3
- import "core-js/modules/es.function.bind.js";
4
1
  /**
5
2
  * File: /auth/Authenticated.tsx
6
3
  * Project: app
@@ -27,27 +24,19 @@ import "core-js/modules/es.function.bind.js";
27
24
 
28
25
  import React from "react";
29
26
  import { useLogin, useKeycloak } from "./hooks";
30
- export var Authenticated = function Authenticated(props) {
31
- var _this2 = this;
32
- _newArrowCheck(this, _this);
33
- var _useKeycloak = useKeycloak(),
34
- authenticated = _useKeycloak.authenticated;
35
- var login = useLogin(props.loginRoute);
27
+ export const Authenticated = props => {
28
+ const {
29
+ authenticated
30
+ } = useKeycloak();
31
+ const login = useLogin(props.loginRoute);
36
32
  if (!props.disabled && !authenticated) {
37
33
  if (authenticated === false) login();
38
- var LoggedOutComponent = props.loggedOutComponent || function () {
39
- _newArrowCheck(this, _this2);
40
- return null;
41
- }.bind(this);
34
+ const LoggedOutComponent = props.loggedOutComponent || (() => null);
42
35
  return /*#__PURE__*/React.createElement(LoggedOutComponent, null);
43
36
  }
44
37
  return /*#__PURE__*/React.createElement(React.Fragment, null, props.children);
45
- }.bind(this);
38
+ };
46
39
  export function withAuthenticated(Component) {
47
- var _this3 = this;
48
- return function (props) {
49
- _newArrowCheck(this, _this3);
50
- return /*#__PURE__*/React.createElement(Authenticated, null, /*#__PURE__*/React.createElement(Component, props));
51
- }.bind(this);
40
+ return props => /*#__PURE__*/React.createElement(Authenticated, null, /*#__PURE__*/React.createElement(Component, props));
52
41
  }
53
42
  //# sourceMappingURL=Authenticated.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Authenticated.js","names":["React","useLogin","useKeycloak","Authenticated","props","authenticated","login","loginRoute","disabled","LoggedOutComponent","loggedOutComponent","children","withAuthenticated","Component"],"sources":["../src/Authenticated.tsx"],"sourcesContent":["/**\n * File: /auth/Authenticated.tsx\n * Project: app\n * File Created: 08-11-2022 05:58:23\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 06:26:38\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, FC, ReactNode } from \"react\";\nimport { useLogin, useKeycloak } from \"./hooks\";\n\nexport interface AuthenticatedProps {\n children: ReactNode;\n disabled?: boolean;\n loggedOutComponent?: ComponentType;\n loginRoute?: string;\n}\n\nexport const Authenticated: FC<AuthenticatedProps> = (\n props: AuthenticatedProps\n) => {\n const { authenticated } = useKeycloak();\n const login = useLogin(props.loginRoute);\n if (!props.disabled && !authenticated) {\n if (authenticated === false) login();\n const LoggedOutComponent = props.loggedOutComponent || (() => null);\n return <LoggedOutComponent />;\n }\n return <>{props.children}</>;\n};\n\nexport function withAuthenticated<P extends object>(\n Component: ComponentType<P>\n) {\n return (props: P) => (\n <Authenticated>\n <Component {...props} />\n </Authenticated>\n );\n}\n"],"mappings":";;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAwC,OAAO;AAC3D,SAASC,QAAQ,EAAEC,WAAW;AAS9B,OAAO,IAAMC,aAAqC,GAAG,uBACnDC,KAAyB,EACtB;EAAA;EAAA;EACH,mBAA0BF,WAAW,EAAE;IAA/BG,aAAa,gBAAbA,aAAa;EACrB,IAAMC,KAAK,GAAGL,QAAQ,CAACG,KAAK,CAACG,UAAU,CAAC;EACxC,IAAI,CAACH,KAAK,CAACI,QAAQ,IAAI,CAACH,aAAa,EAAE;IACrC,IAAIA,aAAa,KAAK,KAAK,EAAEC,KAAK,EAAE;IACpC,IAAMG,kBAAkB,GAAGL,KAAK,CAACM,kBAAkB,IAAK;MAAA;MAAA,OAAM,IAAI;IAAA,YAAC;IACnE,oBAAO,oBAAC,kBAAkB,OAAG;EAC/B;EACA,oBAAO,0CAAGN,KAAK,CAACO,QAAQ,CAAI;AAC9B,CAAC;AAED,OAAO,SAASC,iBAAiB,CAC/BC,SAA2B,EAC3B;EAAA;EACA,OAAO,UAACT,KAAQ;IAAA;IAAA,oBACd,oBAAC,aAAa,qBACZ,oBAAC,SAAS,EAAKA,KAAK,CAAI,CACV;EAAA,CACjB;AACH"}
1
+ {"version":3,"file":"Authenticated.js","names":["React","useLogin","useKeycloak","Authenticated","props","authenticated","login","loginRoute","disabled","LoggedOutComponent","loggedOutComponent","children","withAuthenticated","Component"],"sources":["../src/Authenticated.tsx"],"sourcesContent":["/**\n * File: /auth/Authenticated.tsx\n * Project: app\n * File Created: 08-11-2022 05:58:23\n * Author: Clay Risser\n * -----\n * Last Modified: 22-11-2022 06:26:38\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ComponentType, FC, ReactNode } from \"react\";\nimport { useLogin, useKeycloak } from \"./hooks\";\n\nexport interface AuthenticatedProps {\n children: ReactNode;\n disabled?: boolean;\n loggedOutComponent?: ComponentType;\n loginRoute?: string;\n}\n\nexport const Authenticated: FC<AuthenticatedProps> = (\n props: AuthenticatedProps\n) => {\n const { authenticated } = useKeycloak();\n const login = useLogin(props.loginRoute);\n if (!props.disabled && !authenticated) {\n if (authenticated === false) login();\n const LoggedOutComponent = props.loggedOutComponent || (() => null);\n return <LoggedOutComponent />;\n }\n return <>{props.children}</>;\n};\n\nexport function withAuthenticated<P extends object>(\n Component: ComponentType<P>\n) {\n return (props: P) => (\n <Authenticated>\n <Component {...props} />\n </Authenticated>\n );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAOA,KAAK,MAAwC,OAAO;AAC3D,SAASC,QAAQ,EAAEC,WAAW;AAS9B,OAAO,MAAMC,aAAqC,GAChDC,KAAyB,IACtB;EACH,MAAM;IAAEC;EAAc,CAAC,GAAGH,WAAW,EAAE;EACvC,MAAMI,KAAK,GAAGL,QAAQ,CAACG,KAAK,CAACG,UAAU,CAAC;EACxC,IAAI,CAACH,KAAK,CAACI,QAAQ,IAAI,CAACH,aAAa,EAAE;IACrC,IAAIA,aAAa,KAAK,KAAK,EAAEC,KAAK,EAAE;IACpC,MAAMG,kBAAkB,GAAGL,KAAK,CAACM,kBAAkB,KAAK,MAAM,IAAI,CAAC;IACnE,oBAAO,oBAAC,kBAAkB,OAAG;EAC/B;EACA,oBAAO,0CAAGN,KAAK,CAACO,QAAQ,CAAI;AAC9B,CAAC;AAED,OAAO,SAASC,iBAAiB,CAC/BC,SAA2B,EAC3B;EACA,OAAQT,KAAQ,iBACd,oBAAC,aAAa,qBACZ,oBAAC,SAAS,EAAKA,KAAK,CAAI,CAE3B;AACH"}
package/esm/authConfig.js CHANGED
@@ -23,8 +23,8 @@
23
23
  */
24
24
 
25
25
  import { createContext } from "react";
26
- export var defaultAuthConfig = {
26
+ export const defaultAuthConfig = {
27
27
  ssr: true
28
28
  };
29
- export var AuthConfigContext = /*#__PURE__*/createContext(defaultAuthConfig);
29
+ export const AuthConfigContext = /*#__PURE__*/createContext(defaultAuthConfig);
30
30
  //# sourceMappingURL=authConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"authConfig.js","names":["createContext","defaultAuthConfig","ssr","AuthConfigContext"],"sources":["../src/authConfig.ts"],"sourcesContent":["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from \"react\";\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,OAAO;AAErC,OAAO,IAAMC,iBAA6B,GAAG;EAC3CC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,IAAMC,iBAAiB,gBAAGH,aAAa,CAAaC,iBAAiB,CAAC"}
1
+ {"version":3,"file":"authConfig.js","names":["createContext","defaultAuthConfig","ssr","AuthConfigContext"],"sources":["../src/authConfig.ts"],"sourcesContent":["/**\n * File: /src/authConfig.ts\n * Project: app\n * File Created: 08-11-2022 09:21:15\n * Author: Clay Risser\n * -----\n * Last Modified: 25-11-2022 10:29:29\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2021 - 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createContext } from \"react\";\n\nexport const defaultAuthConfig: AuthConfig = {\n ssr: true,\n};\n\nexport const AuthConfigContext = createContext<AuthConfig>(defaultAuthConfig);\n\nexport interface AuthConfig {\n debug?: boolean;\n loginRoute?: string;\n messageHandlerKeys?: string[];\n ssr?: boolean;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAASA,aAAa,QAAQ,OAAO;AAErC,OAAO,MAAMC,iBAA6B,GAAG;EAC3CC,GAAG,EAAE;AACP,CAAC;AAED,OAAO,MAAMC,iBAAiB,gBAAGH,aAAa,CAAaC,iBAAiB,CAAC"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * File: /src/expo/ExpoKeycloakContext.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:38:25
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ import { createContext } from "react";
26
+ import { KC_INITIAL_VALUE } from "./const";
27
+ export const ExpoKeycloakContext = /*#__PURE__*/createContext(KC_INITIAL_VALUE);
28
+ //# sourceMappingURL=ExpoKeycloakContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoKeycloakContext.js","names":["createContext","KC_INITIAL_VALUE","ExpoKeycloakContext"],"sources":["../../src/expo/ExpoKeycloakContext.ts"],"sourcesContent":["/**\n * File: /src/expo/ExpoKeycloakContext.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:38:25\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AuthRequestPromptOptions,\n AuthSessionResult,\n TokenResponse,\n} from \"expo-auth-session\";\nimport { createContext } from \"react\";\nimport { KC_INITIAL_VALUE } from \"./const\";\n\nexport const ExpoKeycloakContext = createContext<{\n ready: boolean;\n isLoggedIn?: boolean;\n login: (\n options?: AuthRequestPromptOptions\n ) => Promise<AuthSessionResult | undefined>;\n logout: () => undefined;\n token: TokenResponse | null;\n}>(KC_INITIAL_VALUE);\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,aAAa,QAAQ,OAAO;AACrC,SAASC,gBAAgB;AAEzB,OAAO,MAAMC,mBAAmB,gBAAGF,aAAa,CAQ7CC,gBAAgB,CAAC"}
@@ -0,0 +1,113 @@
1
+ /**
2
+ * File: /src/expo/KeycloakProvider.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:06:40
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ import React, { useCallback, useEffect } from "react";
26
+ import { Platform } from "react-native";
27
+ import * as AuthSession from "expo-auth-session";
28
+ import { useAuthRequest, useAutoDiscovery } from "expo-auth-session";
29
+ import { ExpoKeycloakContext } from "./ExpoKeycloakContext";
30
+ import { useTokenStorage } from "./useTokenStorage";
31
+ import { handleTokenExchange, getRealmURL } from "./helpers";
32
+ import { NATIVE_REDIRECT_PATH } from "./const";
33
+ export const ExpoKeycloakProvider = _ref => {
34
+ let {
35
+ realm,
36
+ clientId,
37
+ url,
38
+ extraParams,
39
+ children,
40
+ ...options
41
+ } = _ref;
42
+ const discovery = useAutoDiscovery(getRealmURL({
43
+ realm,
44
+ url
45
+ }));
46
+ const redirectUri = AuthSession.makeRedirectUri({
47
+ native: `${options.scheme ?? "exp"}://${options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH}`,
48
+ useProxy: !options.scheme
49
+ });
50
+ const config = {
51
+ clientId,
52
+ extraParams,
53
+ realm,
54
+ redirectUri,
55
+ url
56
+ };
57
+ const [request, response, promptAsync] = useAuthRequest({
58
+ usePKCE: false,
59
+ ...config
60
+ }, discovery);
61
+ const [currentToken, updateToken] = useTokenStorage(options, config, discovery);
62
+ const handleLogin = useCallback(function () {
63
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
+ return promptAsync(options);
65
+ }, [request]);
66
+ function handleLogout() {
67
+ if (!currentToken) throw new Error("Not logged in.");
68
+ try {
69
+ if (discovery !== null && discovery !== void 0 && discovery.revocationEndpoint) {
70
+ AuthSession.revokeAsync({
71
+ token: currentToken === null || currentToken === void 0 ? void 0 : currentToken.accessToken,
72
+ ...config
73
+ }, discovery);
74
+ }
75
+ if (discovery !== null && discovery !== void 0 && discovery.endSessionEndpoint) {
76
+ fetch(`${discovery.endSessionEndpoint}`, {
77
+ method: "POST",
78
+ headers: {
79
+ "Content-Type": "application/x-www-form-urlencoded"
80
+ },
81
+ body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`
82
+ });
83
+ }
84
+ if (Platform.OS === "ios") {
85
+ AuthSession.dismiss();
86
+ }
87
+ } catch (error) {
88
+ console.log(error);
89
+ }
90
+ updateToken(null);
91
+ return undefined;
92
+ }
93
+ useEffect(() => {
94
+ if (response) {
95
+ handleTokenExchange({
96
+ response,
97
+ discovery: discovery,
98
+ config
99
+ }).then(updateToken);
100
+ }
101
+ }, [response]);
102
+ return /*#__PURE__*/React.createElement(ExpoKeycloakContext.Provider, {
103
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
104
+ value: {
105
+ isLoggedIn: currentToken === undefined ? undefined : !!currentToken,
106
+ login: handleLogin,
107
+ logout: handleLogout,
108
+ ready: discovery !== null && request !== null && currentToken !== undefined,
109
+ token: currentToken
110
+ }
111
+ }, children);
112
+ };
113
+ //# sourceMappingURL=ExpoKeycloakProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoKeycloakProvider.js","names":["React","useCallback","useEffect","Platform","AuthSession","useAuthRequest","useAutoDiscovery","ExpoKeycloakContext","useTokenStorage","handleTokenExchange","getRealmURL","NATIVE_REDIRECT_PATH","ExpoKeycloakProvider","realm","clientId","url","extraParams","children","options","discovery","redirectUri","makeRedirectUri","native","scheme","nativeRedirectPath","useProxy","config","request","response","promptAsync","usePKCE","currentToken","updateToken","handleLogin","handleLogout","Error","revocationEndpoint","revokeAsync","token","accessToken","endSessionEndpoint","fetch","method","headers","body","refreshToken","OS","dismiss","error","console","log","undefined","then","isLoggedIn","login","logout","ready"],"sources":["../../src/expo/ExpoKeycloakProvider.tsx"],"sourcesContent":["/**\n * File: /src/expo/KeycloakProvider.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:06:40\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ReactNode, useCallback, useEffect } from \"react\";\nimport { Platform } from \"react-native\";\nimport * as AuthSession from \"expo-auth-session\";\nimport {\n useAuthRequest,\n useAutoDiscovery,\n AuthRequestConfig,\n} from \"expo-auth-session\";\nimport { ExpoKeycloakContext } from \"./ExpoKeycloakContext\";\nimport { useTokenStorage } from \"./useTokenStorage\";\nimport { handleTokenExchange, getRealmURL } from \"./helpers\";\nimport { NATIVE_REDIRECT_PATH } from \"./const\";\n\nexport interface IKeycloakConfiguration extends Partial<AuthRequestConfig> {\n children: ReactNode;\n clientId: string;\n disableAutoRefresh?: boolean;\n nativeRedirectPath?: string;\n realm: string;\n refreshTimeBuffer?: number;\n scheme?: string;\n tokenStorageKey?: string;\n url: string;\n}\n\nexport const ExpoKeycloakProvider = ({\n realm,\n clientId,\n url,\n extraParams,\n children,\n ...options\n}: IKeycloakConfiguration) => {\n const discovery = useAutoDiscovery(getRealmURL({ realm, url }));\n const redirectUri = AuthSession.makeRedirectUri({\n native: `${options.scheme ?? \"exp\"}://${\n options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH\n }`,\n useProxy: !options.scheme,\n });\n const config = {\n clientId,\n extraParams,\n realm,\n redirectUri,\n url,\n };\n const [request, response, promptAsync] = useAuthRequest(\n { usePKCE: false, ...config },\n discovery\n );\n const [currentToken, updateToken] = useTokenStorage(\n options,\n config,\n discovery!\n );\n\n const handleLogin = useCallback(\n (options: AuthSession.AuthRequestPromptOptions = {}) =>\n promptAsync(options),\n [request]\n );\n\n function handleLogout() {\n if (!currentToken) throw new Error(\"Not logged in.\");\n try {\n if (discovery?.revocationEndpoint) {\n AuthSession.revokeAsync(\n { token: currentToken?.accessToken, ...config },\n discovery\n );\n }\n if (discovery?.endSessionEndpoint) {\n fetch(`${discovery.endSessionEndpoint}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`,\n });\n }\n if (Platform.OS === \"ios\") {\n AuthSession.dismiss();\n }\n } catch (error) {\n console.log(error);\n }\n updateToken(null);\n return undefined;\n }\n\n useEffect(() => {\n if (response) {\n handleTokenExchange({ response, discovery: discovery!, config }).then(\n updateToken\n );\n }\n }, [response]);\n\n return (\n <ExpoKeycloakContext.Provider\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n value={{\n isLoggedIn: currentToken === undefined ? undefined : !!currentToken,\n login: handleLogin,\n logout: handleLogout,\n ready:\n discovery !== null && request !== null && currentToken !== undefined,\n token: currentToken,\n }}\n >\n {children}\n </ExpoKeycloakContext.Provider>\n );\n};\n"],"mappings":"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"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * File: /src/expo/KeycloakContext.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:25:18
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ import { createContext } from "react";
26
+ import { KC_INITIAL_VALUE } from "./const";
27
+ export var KeycloakContext = /*#__PURE__*/createContext(KC_INITIAL_VALUE);
28
+ //# sourceMappingURL=KeycloakContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeycloakContext.js","names":["createContext","KC_INITIAL_VALUE","KeycloakContext"],"sources":["../../src/expo/KeycloakContext.ts"],"sourcesContent":["/**\n * File: /src/expo/KeycloakContext.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:25:18\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AuthRequestPromptOptions,\n AuthSessionResult,\n TokenResponse,\n} from \"expo-auth-session\";\nimport { createContext } from \"react\";\nimport { KC_INITIAL_VALUE } from \"./const\";\n\nexport const KeycloakContext = createContext<{\n ready: boolean;\n isLoggedIn?: boolean;\n login: (\n options?: AuthRequestPromptOptions\n ) => Promise<AuthSessionResult | undefined>;\n logout: () => undefined;\n token: TokenResponse | null;\n}>(KC_INITIAL_VALUE);\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAOA,SAASA,aAAa,QAAQ,OAAO;AACrC,SAASC,gBAAgB;AAEzB,OAAO,IAAMC,eAAe,gBAAGF,aAAa,CAQzCC,gBAAgB,CAAC"}
@@ -0,0 +1,142 @@
1
+ import "core-js/modules/es.object.keys.js";
2
+ import "core-js/modules/es.symbol.js";
3
+ import "core-js/modules/es.array.filter.js";
4
+ import "core-js/modules/es.object.get-own-property-descriptor.js";
5
+ import "core-js/modules/es.array.for-each.js";
6
+ import "core-js/modules/web.dom-collections.for-each.js";
7
+ import "core-js/modules/es.object.get-own-property-descriptors.js";
8
+ import "core-js/modules/es.object.define-properties.js";
9
+ import "core-js/modules/es.object.define-property.js";
10
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
11
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
12
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
13
+ import _newArrowCheck from "@babel/runtime/helpers/newArrowCheck";
14
+ var _excluded = ["realm", "clientId", "url", "extraParams", "children"];
15
+ var _this = this;
16
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
17
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
18
+ import "core-js/modules/es.function.bind.js";
19
+ import "core-js/modules/es.array.concat.js";
20
+ import "core-js/modules/es.object.to-string.js";
21
+ import "core-js/modules/es.promise.js";
22
+ /**
23
+ * File: /src/expo/KeycloakProvider.ts
24
+ * Project: @multiplatform.one/keycloak
25
+ * File Created: 26-11-2022 06:58:16
26
+ * Author: Clay Risser
27
+ * -----
28
+ * Last Modified: 26-11-2022 08:06:40
29
+ * Modified By: Clay Risser
30
+ * -----
31
+ * Risser Labs LLC (c) Copyright 2022
32
+ *
33
+ * Licensed under the Apache License, Version 2.0 (the "License");
34
+ * you may not use this file except in compliance with the License.
35
+ * You may obtain a copy of the License at
36
+ *
37
+ * http://www.apache.org/licenses/LICENSE-2.0
38
+ *
39
+ * Unless required by applicable law or agreed to in writing, software
40
+ * distributed under the License is distributed on an "AS IS" BASIS,
41
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
42
+ * See the License for the specific language governing permissions and
43
+ * limitations under the License.
44
+ */
45
+
46
+ import React, { useCallback, useEffect } from "react";
47
+ import { Platform } from "react-native";
48
+ import * as AuthSession from "expo-auth-session";
49
+ import { useAuthRequest, useAutoDiscovery } from "expo-auth-session";
50
+ import { KeycloakContext } from "./KeycloakContext";
51
+ import { useTokenStorage } from "./useTokenStorage";
52
+ import { handleTokenExchange, getRealmURL } from "./helpers";
53
+ import { NATIVE_REDIRECT_PATH } from "./const";
54
+ export var KeycloakProvider = function KeycloakProvider(_ref) {
55
+ var _options$scheme,
56
+ _options$nativeRedire,
57
+ _this2 = this;
58
+ _newArrowCheck(this, _this);
59
+ var realm = _ref.realm,
60
+ clientId = _ref.clientId,
61
+ url = _ref.url,
62
+ extraParams = _ref.extraParams,
63
+ children = _ref.children,
64
+ options = _objectWithoutProperties(_ref, _excluded);
65
+ var discovery = useAutoDiscovery(getRealmURL({
66
+ realm: realm,
67
+ url: url
68
+ }));
69
+ var redirectUri = AuthSession.makeRedirectUri({
70
+ "native": "".concat((_options$scheme = options.scheme) !== null && _options$scheme !== void 0 ? _options$scheme : "exp", "://").concat((_options$nativeRedire = options.nativeRedirectPath) !== null && _options$nativeRedire !== void 0 ? _options$nativeRedire : NATIVE_REDIRECT_PATH),
71
+ useProxy: !options.scheme
72
+ });
73
+ var config = {
74
+ clientId: clientId,
75
+ extraParams: extraParams,
76
+ realm: realm,
77
+ redirectUri: redirectUri,
78
+ url: url
79
+ };
80
+ var _useAuthRequest = useAuthRequest(_objectSpread({
81
+ usePKCE: false
82
+ }, config), discovery),
83
+ _useAuthRequest2 = _slicedToArray(_useAuthRequest, 3),
84
+ request = _useAuthRequest2[0],
85
+ response = _useAuthRequest2[1],
86
+ promptAsync = _useAuthRequest2[2];
87
+ var _useTokenStorage = useTokenStorage(options, config, discovery),
88
+ _useTokenStorage2 = _slicedToArray(_useTokenStorage, 2),
89
+ currentToken = _useTokenStorage2[0],
90
+ updateToken = _useTokenStorage2[1];
91
+ var handleLogin = useCallback(function () {
92
+ var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
93
+ return promptAsync(options);
94
+ }, [request]);
95
+ function handleLogout() {
96
+ if (!currentToken) throw new Error("Not logged in.");
97
+ try {
98
+ if (discovery !== null && discovery !== void 0 && discovery.revocationEndpoint) {
99
+ AuthSession.revokeAsync(_objectSpread({
100
+ token: currentToken === null || currentToken === void 0 ? void 0 : currentToken.accessToken
101
+ }, config), discovery);
102
+ }
103
+ if (discovery !== null && discovery !== void 0 && discovery.endSessionEndpoint) {
104
+ fetch("".concat(discovery.endSessionEndpoint), {
105
+ method: "POST",
106
+ headers: {
107
+ "Content-Type": "application/x-www-form-urlencoded"
108
+ },
109
+ body: "client_id=".concat(clientId, "&refresh_token=").concat(currentToken.refreshToken)
110
+ });
111
+ }
112
+ if (Platform.OS === "ios") {
113
+ AuthSession.dismiss();
114
+ }
115
+ } catch (error) {
116
+ console.log(error);
117
+ }
118
+ updateToken(null);
119
+ return undefined;
120
+ }
121
+ useEffect(function () {
122
+ _newArrowCheck(this, _this2);
123
+ if (response) {
124
+ handleTokenExchange({
125
+ response: response,
126
+ discovery: discovery,
127
+ config: config
128
+ }).then(updateToken);
129
+ }
130
+ }.bind(this), [response]);
131
+ return /*#__PURE__*/React.createElement(KeycloakContext.Provider, {
132
+ // eslint-disable-next-line react/jsx-no-constructed-context-values
133
+ value: {
134
+ isLoggedIn: currentToken === undefined ? undefined : !!currentToken,
135
+ login: handleLogin,
136
+ logout: handleLogout,
137
+ ready: discovery !== null && request !== null && currentToken !== undefined,
138
+ token: currentToken
139
+ }
140
+ }, children);
141
+ }.bind(this);
142
+ //# sourceMappingURL=KeycloakProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KeycloakProvider.js","names":["React","useCallback","useEffect","Platform","AuthSession","useAuthRequest","useAutoDiscovery","KeycloakContext","useTokenStorage","handleTokenExchange","getRealmURL","NATIVE_REDIRECT_PATH","KeycloakProvider","realm","clientId","url","extraParams","children","options","discovery","redirectUri","makeRedirectUri","scheme","nativeRedirectPath","useProxy","config","usePKCE","request","response","promptAsync","currentToken","updateToken","handleLogin","handleLogout","Error","revocationEndpoint","revokeAsync","token","accessToken","endSessionEndpoint","fetch","method","headers","body","refreshToken","OS","dismiss","error","console","log","undefined","then","isLoggedIn","login","logout","ready"],"sources":["../../src/expo/KeycloakProvider.tsx"],"sourcesContent":["/**\n * File: /src/expo/KeycloakProvider.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:06:40\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport React, { ReactNode, useCallback, useEffect } from \"react\";\nimport { Platform } from \"react-native\";\nimport * as AuthSession from \"expo-auth-session\";\nimport {\n useAuthRequest,\n useAutoDiscovery,\n AuthRequestConfig,\n} from \"expo-auth-session\";\nimport { KeycloakContext } from \"./KeycloakContext\";\nimport { useTokenStorage } from \"./useTokenStorage\";\nimport { handleTokenExchange, getRealmURL } from \"./helpers\";\nimport { NATIVE_REDIRECT_PATH } from \"./const\";\n\nexport interface IKeycloakConfiguration extends Partial<AuthRequestConfig> {\n children: ReactNode;\n clientId: string;\n disableAutoRefresh?: boolean;\n nativeRedirectPath?: string;\n realm: string;\n refreshTimeBuffer?: number;\n scheme?: string;\n tokenStorageKey?: string;\n url: string;\n}\n\nexport const KeycloakProvider = ({\n realm,\n clientId,\n url,\n extraParams,\n children,\n ...options\n}: IKeycloakConfiguration) => {\n const discovery = useAutoDiscovery(getRealmURL({ realm, url }));\n const redirectUri = AuthSession.makeRedirectUri({\n native: `${options.scheme ?? \"exp\"}://${\n options.nativeRedirectPath ?? NATIVE_REDIRECT_PATH\n }`,\n useProxy: !options.scheme,\n });\n const config = {\n clientId,\n extraParams,\n realm,\n redirectUri,\n url,\n };\n const [request, response, promptAsync] = useAuthRequest(\n { usePKCE: false, ...config },\n discovery\n );\n const [currentToken, updateToken] = useTokenStorage(\n options,\n config,\n discovery!\n );\n\n const handleLogin = useCallback(\n (options: AuthSession.AuthRequestPromptOptions = {}) =>\n promptAsync(options),\n [request]\n );\n\n function handleLogout() {\n if (!currentToken) throw new Error(\"Not logged in.\");\n try {\n if (discovery?.revocationEndpoint) {\n AuthSession.revokeAsync(\n { token: currentToken?.accessToken, ...config },\n discovery\n );\n }\n if (discovery?.endSessionEndpoint) {\n fetch(`${discovery.endSessionEndpoint}`, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n },\n body: `client_id=${clientId}&refresh_token=${currentToken.refreshToken}`,\n });\n }\n if (Platform.OS === \"ios\") {\n AuthSession.dismiss();\n }\n } catch (error) {\n console.log(error);\n }\n updateToken(null);\n return undefined;\n }\n\n useEffect(() => {\n if (response) {\n handleTokenExchange({ response, discovery: discovery!, config }).then(\n updateToken\n );\n }\n }, [response]);\n\n return (\n <KeycloakContext.Provider\n // eslint-disable-next-line react/jsx-no-constructed-context-values\n value={{\n isLoggedIn: currentToken === undefined ? undefined : !!currentToken,\n login: handleLogin,\n logout: handleLogout,\n ready:\n discovery !== null && request !== null && currentToken !== undefined,\n token: currentToken,\n }}\n >\n {children}\n </KeycloakContext.Provider>\n );\n};\n"],"mappings":"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"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * File: /src/expo/const.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:17:10
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ const logger = console;
26
+ export const KC_INITIAL_VALUE = {
27
+ ready: false,
28
+ isLoggedIn: false,
29
+ login: async () => {
30
+ logger.error("kc not initialized");
31
+ return undefined;
32
+ },
33
+ logout: () => {
34
+ logger.error("not logged in");
35
+ return undefined;
36
+ },
37
+ token: null
38
+ };
39
+ export const NATIVE_REDIRECT_PATH = "auth/redirect";
40
+ export const TOKEN_STORAGE_KEY = "keycloak_token";
41
+ export const REFRESH_TIME_BUFFER = 20;
42
+ //# sourceMappingURL=const.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"const.js","names":["logger","console","KC_INITIAL_VALUE","ready","isLoggedIn","login","error","undefined","logout","token","NATIVE_REDIRECT_PATH","TOKEN_STORAGE_KEY","REFRESH_TIME_BUFFER"],"sources":["../../src/expo/const.ts"],"sourcesContent":["/**\n * File: /src/expo/const.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:17:10\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst logger = console;\n\nexport const KC_INITIAL_VALUE = {\n ready: false,\n isLoggedIn: false,\n login: async () => {\n logger.error(\"kc not initialized\");\n return undefined;\n },\n logout: () => {\n logger.error(\"not logged in\");\n return undefined;\n },\n token: null,\n};\nexport const NATIVE_REDIRECT_PATH = \"auth/redirect\";\nexport const TOKEN_STORAGE_KEY = \"keycloak_token\";\nexport const REFRESH_TIME_BUFFER = 20;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAMA,MAAM,GAAGC,OAAO;AAEtB,OAAO,MAAMC,gBAAgB,GAAG;EAC9BC,KAAK,EAAE,KAAK;EACZC,UAAU,EAAE,KAAK;EACjBC,KAAK,EAAE,YAAY;IACjBL,MAAM,CAACM,KAAK,CAAC,oBAAoB,CAAC;IAClC,OAAOC,SAAS;EAClB,CAAC;EACDC,MAAM,EAAE,MAAM;IACZR,MAAM,CAACM,KAAK,CAAC,eAAe,CAAC;IAC7B,OAAOC,SAAS;EAClB,CAAC;EACDE,KAAK,EAAE;AACT,CAAC;AACD,OAAO,MAAMC,oBAAoB,GAAG,eAAe;AACnD,OAAO,MAAMC,iBAAiB,GAAG,gBAAgB;AACjD,OAAO,MAAMC,mBAAmB,GAAG,EAAE"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * File: /src/expo/helpers.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:11:15
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ import { exchangeCodeAsync } from "expo-auth-session";
26
+ export function getRealmURL(config) {
27
+ const {
28
+ url,
29
+ realm
30
+ } = config;
31
+ const slash = url.endsWith("/") ? "" : "/";
32
+ return `${url + slash}realms/${encodeURIComponent(realm)}`;
33
+ }
34
+ export function getCurrentTimeInSeconds() {
35
+ return Math.floor(Date.now() / 1000);
36
+ }
37
+ export async function handleTokenExchange(_ref) {
38
+ let {
39
+ response,
40
+ discovery,
41
+ config
42
+ } = _ref;
43
+ try {
44
+ if ((response === null || response === void 0 ? void 0 : response.type) === "success" && !!(discovery !== null && discovery !== void 0 && discovery.tokenEndpoint)) {
45
+ return exchangeCodeAsync({
46
+ code: response.params.code,
47
+ ...config
48
+ }, discovery);
49
+ }
50
+ if ((response === null || response === void 0 ? void 0 : response.type) === "error") return null;
51
+ return null;
52
+ } catch (error) {
53
+ return null;
54
+ }
55
+ }
56
+ //# sourceMappingURL=helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"helpers.js","names":["exchangeCodeAsync","getRealmURL","config","url","realm","slash","endsWith","encodeURIComponent","getCurrentTimeInSeconds","Math","floor","Date","now","handleTokenExchange","response","discovery","type","tokenEndpoint","code","params","error"],"sources":["../../src/expo/helpers.ts"],"sourcesContent":["/**\n * File: /src/expo/helpers.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:11:15\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {\n AccessTokenRequestConfig,\n exchangeCodeAsync,\n DiscoveryDocument,\n AuthSessionResult,\n} from \"expo-auth-session\";\n\nexport function getRealmURL(config: RealmURLConfig) {\n const { url, realm } = config;\n const slash = url.endsWith(\"/\") ? \"\" : \"/\";\n return `${url + slash}realms/${encodeURIComponent(realm)}`;\n}\n\nexport function getCurrentTimeInSeconds() {\n return Math.floor(Date.now() / 1000);\n}\n\nexport async function handleTokenExchange({\n response,\n discovery,\n config,\n}: TokenExchange) {\n try {\n if (response?.type === \"success\" && !!discovery?.tokenEndpoint) {\n return exchangeCodeAsync(\n { code: response.params.code, ...config },\n discovery\n );\n }\n if (response?.type === \"error\") return null;\n return null;\n } catch (error) {\n return null;\n }\n}\n\nexport interface TokenExchange {\n response: AuthSessionResult;\n discovery: Pick<DiscoveryDocument, \"tokenEndpoint\">;\n config: Omit<AccessTokenRequestConfig, \"code\"> & { code?: string };\n}\n\nexport interface TokenExchangeDiscovery {\n tokenEndpoint?: string;\n}\n\nexport interface RealmURLConfig {\n realm: string;\n url: string;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,SAEEA,iBAAiB,QAGZ,mBAAmB;AAE1B,OAAO,SAASC,WAAW,CAACC,MAAsB,EAAE;EAClD,MAAM;IAAEC,GAAG;IAAEC;EAAM,CAAC,GAAGF,MAAM;EAC7B,MAAMG,KAAK,GAAGF,GAAG,CAACG,QAAQ,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,GAAG;EAC1C,OAAQ,GAAEH,GAAG,GAAGE,KAAM,UAASE,kBAAkB,CAACH,KAAK,CAAE,EAAC;AAC5D;AAEA,OAAO,SAASI,uBAAuB,GAAG;EACxC,OAAOC,IAAI,CAACC,KAAK,CAACC,IAAI,CAACC,GAAG,EAAE,GAAG,IAAI,CAAC;AACtC;AAEA,OAAO,eAAeC,mBAAmB,OAIvB;EAAA,IAJwB;IACxCC,QAAQ;IACRC,SAAS;IACTb;EACa,CAAC;EACd,IAAI;IACF,IAAI,CAAAY,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,SAAS,IAAI,CAAC,EAACD,SAAS,aAATA,SAAS,eAATA,SAAS,CAAEE,aAAa,GAAE;MAC9D,OAAOjB,iBAAiB,CACtB;QAAEkB,IAAI,EAAEJ,QAAQ,CAACK,MAAM,CAACD,IAAI;QAAE,GAAGhB;MAAO,CAAC,EACzCa,SAAS,CACV;IACH;IACA,IAAI,CAAAD,QAAQ,aAARA,QAAQ,uBAARA,QAAQ,CAAEE,IAAI,MAAK,OAAO,EAAE,OAAO,IAAI;IAC3C,OAAO,IAAI;EACb,CAAC,CAAC,OAAOI,KAAK,EAAE;IACd,OAAO,IAAI;EACb;AACF"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * File: /src/expo/index.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:38:41
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ export * from "./ExpoKeycloakProvider";
26
+ export * from "./useExpoKeycloak";
27
+ export * from "./const";
28
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/expo/index.ts"],"sourcesContent":["/**\n * File: /src/expo/index.ts\n * Project: @multiplatform.one/keycloak\n * File Created: 26-11-2022 06:58:16\n * Author: Clay Risser\n * -----\n * Last Modified: 26-11-2022 08:38:41\n * Modified By: Clay Risser\n * -----\n * Risser Labs LLC (c) Copyright 2022\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nexport * from \"./ExpoKeycloakProvider\";\nexport * from \"./useExpoKeycloak\";\nexport * from \"./const\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * File: /src/expo/useExpoKeycloak.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 26-11-2022 06:58:16
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 26-11-2022 08:38:57
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ import { useContext } from "react";
26
+ import { ExpoKeycloakContext } from "./ExpoKeycloakContext";
27
+ export function useExpoKeycloak() {
28
+ const {
29
+ isLoggedIn,
30
+ login,
31
+ logout,
32
+ ready = false,
33
+ token = null
34
+ } = useContext(ExpoKeycloakContext);
35
+ return {
36
+ isLoggedIn,
37
+ login,
38
+ logout,
39
+ ready,
40
+ token: (token === null || token === void 0 ? void 0 : token.accessToken) ?? null,
41
+ refreshToken: (token === null || token === void 0 ? void 0 : token.refreshToken) ?? null
42
+ };
43
+ }
44
+ //# sourceMappingURL=useExpoKeycloak.js.map