@snokam/auth 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +16 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -0
- package/lib/types.d.ts +2 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +31 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Change Log
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
|
+
|
|
6
|
+
# 1.1.0 (2024-07-17)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* paths for auth ([72673fe](https://github.com/snokam/components/commit/72673fec2e81779566283b15d06c2e163667428d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
### Features
|
|
15
|
+
|
|
16
|
+
* add auth package ([26cadad](https://github.com/snokam/components/commit/26cadadfc53812863e10931daff039f00e7c866a))
|
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { RequestContext, ResponseContext } from "./types";
|
|
2
|
+
export interface AuthProps {
|
|
3
|
+
scopes: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare const useAuth: (props: AuthProps) => {
|
|
6
|
+
getToken: () => Promise<any>;
|
|
7
|
+
AuthMiddleware: {
|
|
8
|
+
new (): {
|
|
9
|
+
pre(context: RequestContext): Promise<RequestContext>;
|
|
10
|
+
post(context: ResponseContext): Promise<ResponseContext>;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
export declare const useGetToken: ({ scopes }: AuthProps) => () => Promise<any>;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.snokam=t():e.snokam=t()}(this,(()=>(()=>{"use strict";var e={d:(t,o)=>{for(var n in o)e.o(o,n)&&!e.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:o[n]})},o:(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},t={};e.r(t),e.d(t,{useAuth:()=>r,useGetToken:()=>c});const o=require("@azure/msal-react");var n=function(e,t,o,n){return new(o||(o=Promise))((function(r,c){function i(e){try{a(n.next(e))}catch(e){c(e)}}function u(e){try{a(n.throw(e))}catch(e){c(e)}}function a(e){var t;e.done?r(e.value):(t=e.value,t instanceof o?t:new o((function(e){e(t)}))).then(i,u)}a((n=n.apply(e,t||[])).next())}))};const r=e=>{const t=c(e);return{getToken:t,AuthMiddleware:class{pre(e){return n(this,void 0,void 0,(function*(){try{const o=yield t();e.setHeaderParam("Authorization",`Bearer ${o}`)}catch(e){throw console.warn("Failed to acquire token silently",e),e}return e}))}post(e){return n(this,void 0,void 0,(function*(){return e}))}}}},c=({scopes:e})=>{const{instance:t}=(0,o.useMsal)(),r=t.getAllAccounts()[0];return()=>n(void 0,void 0,void 0,(function*(){if(!r)throw new Error("No active account found.");try{const{accessToken:o}=yield t.acquireTokenSilent({scopes:e,account:r});return o}catch(e){throw console.warn("Failed to acquire token silently",e),e}}))};return t})()));
|
|
2
|
+
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IA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Q,YACnC,IACI,MAAM0C,QAAcL,IACpBI,EAAQE,eAAe,gBAAiB,UAAUD,IACtD,CACA,MAAOE,GAEH,MADAC,QAAQC,KAAK,mCAAoCF,GAC3CA,CACV,CACA,OAAOH,CACX,GACJ,CACA,IAAAM,CAAKN,GACD,OAAOvB,EAAUlB,UAAM,OAAQ,GAAQ,YACnC,OAAOyC,CACX,GACJ,GAKH,EAEQH,EAAc,EAAGU,aAC1B,MAAM,SAAEC,IAAa,IAAAC,WACfC,EAAUF,EAASG,iBAAiB,GAC1C,MAAO,IAAMlC,OAAU,OAAQ,OAAQ,GAAQ,YAC3C,IAAKiC,EACD,MAAM,IAAIE,MAAM,4BAEpB,IACI,MAAM,YAAEC,SAAsBL,EAASM,mBAAmB,CACtDP,OAAQA,EACRG,YAEJ,OAAOG,CACX,CACA,MAAOV,GAEH,MADAC,QAAQC,KAAK,mCAAoCF,GAC3CA,CACV,CACJ,GAAE,E","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/define property getters","webpack://snokam/webpack/runtime/hasOwnProperty shorthand","webpack://snokam/webpack/runtime/make namespace object","webpack://snokam/external commonjs \"@azure/msal-react\"","webpack://snokam/./src/index.tsx"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};","const __WEBPACK_NAMESPACE_OBJECT__ = require(\"@azure/msal-react\");","var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {\n function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }\n return new (P || (P = Promise))(function (resolve, reject) {\n function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }\n function rejected(value) { try { step(generator[\"throw\"](value)); } catch (e) { reject(e); } }\n function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }\n step((generator = generator.apply(thisArg, _arguments || [])).next());\n });\n};\nimport { useMsal } from \"@azure/msal-react\";\nexport const useAuth = (props) => {\n const getToken = useGetToken(props);\n class AuthMiddleware {\n pre(context) {\n return __awaiter(this, void 0, void 0, function* () {\n try {\n const token = yield getToken();\n context.setHeaderParam(\"Authorization\", `Bearer ${token}`);\n }\n catch (error) {\n console.warn(\"Failed to acquire token silently\", error);\n throw error;\n }\n return context;\n });\n }\n post(context) {\n return __awaiter(this, void 0, void 0, function* () {\n return context;\n });\n }\n }\n return {\n getToken,\n AuthMiddleware,\n };\n};\nexport const useGetToken = ({ scopes }) => {\n const { instance } = useMsal();\n const account = instance.getAllAccounts()[0];\n return () => __awaiter(void 0, void 0, void 0, function* () {\n if (!account) {\n throw new Error(\"No active account found.\");\n }\n try {\n const { accessToken } = yield instance.acquireTokenSilent({\n scopes: scopes,\n account,\n });\n return accessToken;\n }\n catch (error) {\n console.warn(\"Failed to acquire token silently\", error);\n throw error;\n }\n });\n};\n"],"names":["root","factory","exports","module","define","amd","this","__webpack_require__","definition","key","o","Object","defineProperty","enumerable","get","obj","prop","prototype","hasOwnProperty","call","Symbol","toStringTag","value","require","__awaiter","thisArg","_arguments","P","generator","Promise","resolve","reject","fulfilled","step","next","e","rejected","result","done","then","apply","useAuth","props","getToken","useGetToken","AuthMiddleware","pre","context","token","setHeaderParam","error","console","warn","post","scopes","instance","useMsal","account","getAllAccounts","Error","accessToken","acquireTokenSilent"],"sourceRoot":""}
|
package/lib/types.d.ts
ADDED
package/lib/types.js
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(e,o){"object"==typeof exports&&"object"==typeof module?module.exports=o():"function"==typeof define&&define.amd?define([],o):"object"==typeof exports?exports.snokam=o():e.snokam=o()}(this,(()=>(()=>{"use strict";var e={};return(e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})})(e),e})()));
|
|
2
|
+
//# sourceMappingURL=types.js.map
|
package/lib/types.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","mappings":"CAAA,SAA2CA,EAAMC,GAC1B,iBAAZC,SAA0C,iBAAXC,OACxCA,OAAOD,QAAUD,IACQ,mBAAXG,QAAyBA,OAAOC,IAC9CD,OAAO,GAAIH,GACe,iBAAZC,QACdA,QAAgB,OAAID,IAEpBD,EAAa,OAAIC,GAClB,CATD,CASGK,MAAM,I,mBCRT,I,WCAwB,CAACJ,IACH,oBAAXK,QAA0BA,OAAOC,aAC1CC,OAAOC,eAAeR,EAASK,OAAOC,YAAa,CAAEG,MAAO,WAE7DF,OAAOC,eAAeR,EAAS,aAAc,CAAES,OAAO,GAAO,E","sources":["webpack://snokam/webpack/universalModuleDefinition","webpack://snokam/webpack/bootstrap","webpack://snokam/webpack/runtime/make namespace object"],"sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"snokam\"] = factory();\n\telse\n\t\troot[\"snokam\"] = factory();\n})(this, () => {\nreturn ","// The require scope\nvar __webpack_require__ = {};\n\n","// define __esModule on exports\n__webpack_require__.r = (exports) => {\n\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n\t}\n\tObject.defineProperty(exports, '__esModule', { value: true });\n};"],"names":["root","factory","exports","module","define","amd","this","Symbol","toStringTag","Object","defineProperty","value"],"sourceRoot":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@snokam/auth",
|
|
3
|
+
"description": "Utility functions for authentication",
|
|
4
|
+
"version": "1.1.0",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"package.json",
|
|
10
|
+
"CHANGELOG.md"
|
|
11
|
+
],
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "ssh://git@github.com:snokam/components.git",
|
|
15
|
+
"directory": "@snokam/auth"
|
|
16
|
+
},
|
|
17
|
+
"scripts": {
|
|
18
|
+
"start": "webpack --watch --config=../../webpack/webpack.dev.js",
|
|
19
|
+
"build": "webpack --config=../../webpack/webpack.prod.js",
|
|
20
|
+
"build:doc": "webpack --config=../../webpack/webpack.dev.js",
|
|
21
|
+
"clean": "rm -rf lib"
|
|
22
|
+
},
|
|
23
|
+
"publishConfig": {
|
|
24
|
+
"access": "public"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@azure/msal-react": "^2.0.21",
|
|
28
|
+
"@snokam/employees-client": "^1.0.2"
|
|
29
|
+
},
|
|
30
|
+
"gitHead": "37e7998f963d0540294dffe68d9f17e0fa9bf191"
|
|
31
|
+
}
|