@xwiki/cristal-electron-authentication-github-main 0.24.0 → 0.25.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.
@@ -1 +1 @@
1
- {"version":3,"file":"index.es.js","sources":["../src/storage.ts","../src/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Store from \"electron-store\";\n\nconst tokenTypeKey = \"tokenType\";\n\nconst accessTokenKey = \"accessToken\";\n\ntype StoreType = {\n tokenType: string;\n accessToken: string;\n};\n\nconst schema = {\n tokenType: {\n type: \"string\",\n },\n\n accessToken: {\n type: \"string\",\n },\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"authentication-github-main\",\n schema,\n // TODO: add encryption key\n});\n\nfunction setTokenType(value: string): void {\n storeInstance.set(tokenTypeKey, value);\n}\n\nfunction setAccessToken(value: string): void {\n storeInstance.set(accessTokenKey, value);\n}\n\nfunction getTokenType(): string {\n return storeInstance.get(tokenTypeKey);\n}\n\nfunction getAccessToken(): string {\n return storeInstance.get(accessTokenKey);\n}\n\nfunction deleteTokenType(): void {\n storeInstance.delete(tokenTypeKey);\n}\n\nfunction deleteAccessToken(): void {\n storeInstance.delete(accessTokenKey);\n}\n\nexport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n};\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n} from \"./storage.js\";\nimport axios from \"axios\";\nimport { BrowserWindow, ipcMain } from \"electron\";\nimport type { UserDetails } from \"@xwiki/cristal-authentication-api\";\n\nfunction getAuthorizationValue() {\n return `${getTokenType()} ${getAccessToken()}`;\n}\n\n/**\n * @param browserWindow - the browser window to use for the authentication process\n * @param reload - the reload function\n *\n * @since 0.15\n * @beta\n */\nexport function load(\n browserWindow: BrowserWindow,\n reload: (win: BrowserWindow) => void,\n): void {\n ipcMain.handle(\n \"authentication:github:login\",\n async (\n _event,\n {\n baseUrl,\n deviceCode,\n interval,\n expiresIn,\n }: {\n baseUrl: string;\n deviceCode: string;\n interval: string;\n expiresIn: string;\n },\n ) => {\n const verificationUrl = new URL(`${baseUrl}/device-verify`);\n verificationUrl.searchParams.set(\"device_code\", deviceCode);\n\n // This converts the interval polling time and expiration time provided by\n // GitHub to milliseconds.\n // We need to add a little more delay to the interval when polling, just to\n // be sure that we don't go to fast for GitHub (or we might get rate\n // limited).\n const intervalMs: number = parseInt(interval) * 1000 + 500;\n let expiresInMs: number = parseInt(expiresIn) * 1000;\n\n // This interval handles polling the backend for the access token, using\n // the interval time computed earlier.\n // The backend will return an error until the login process has succeeded.\n const intervalId = setInterval(async () => {\n const response = await fetch(verificationUrl);\n const jsonResponse: {\n error?: string;\n access_token?: string;\n token_type?: string;\n } = await response.json();\n if (!jsonResponse.error) {\n setAccessToken(jsonResponse.access_token!);\n setTokenType(jsonResponse.token_type!);\n clearInterval(intervalId);\n // We reload the content on successful login.\n reload(browserWindow);\n } else if (expiresInMs <= 0) {\n clearInterval(intervalId);\n }\n expiresInMs -= intervalMs;\n }, intervalMs);\n },\n );\n\n ipcMain.handle(\"authentication:github:isLoggedIn\", () => {\n const tokenType = getTokenType();\n const accessTokenKey = getAccessToken();\n return tokenType && accessTokenKey;\n });\n\n ipcMain.handle(\n \"authentication:github:userDetails\",\n async (): Promise<UserDetails> => {\n const userinfoUrl = \"https://api.github.com/user\";\n const data = {\n headers: {\n Authorization: getAuthorizationValue(),\n },\n };\n const {\n data: { login, html_url, name, avatar_url },\n } = await axios.get(userinfoUrl, data);\n\n return { profile: html_url, username: login, name, avatar: avatar_url };\n },\n );\n ipcMain.handle(\"authentication:github:authorizationValue\", () => {\n return {\n tokenType: getTokenType(),\n accessToken: getAccessToken(),\n };\n });\n ipcMain.handle(\"authentication:github:logout\", () => {\n deleteAccessToken();\n deleteTokenType();\n });\n}\n"],"names":["tokenTypeKey","accessTokenKey","schema","storeInstance","Store","setTokenType","value","setAccessToken","getTokenType","getAccessToken","deleteTokenType","deleteAccessToken","getAuthorizationValue","load","browserWindow","reload","ipcMain","_event","baseUrl","deviceCode","interval","expiresIn","verificationUrl","intervalMs","expiresInMs","intervalId","jsonResponse","tokenType","userinfoUrl","data","login","html_url","name","avatar_url","axios"],"mappings":";;;AAsBA,MAAMA,IAAe,aAEfC,IAAiB,eAOjBC,IAAS;AAAA,EACb,WAAW;AAAA,IACT,MAAM;AAAA,EAAA;AAAA,EAGR,aAAa;AAAA,IACX,MAAM;AAAA,EAAA;AAEV,GAEMC,IAAkC,IAAIC,EAAiB;AAAA,EAC3D,MAAM;AAAA,EACN,QAAAF;AAAA;A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A,EACtB,CAAC,GAEDe,EAAQ;AAAA,IACN;AAAA,IACA,YAAkC;AAChC,YAAMY,IAAc,+BACdC,IAAO;AAAA,QACX,SAAS;AAAA,UACP,eAAejB,EAAA;AAAA,QAAsB;AAAA,MACvC,GAEI;AAAA,QACJ,MAAM,EAAE,OAAAkB,GAAO,UAAAC,GAAU,MAAAC,GAAM,YAAAC,EAAA;AAAA,MAAW,IACxC,MAAMC,EAAM,IAAIN,GAAaC,CAAI;AAErC,aAAO,EAAE,SAASE,GAAU,UAAUD,GAAO,MAAAE,GAAM,QAAQC,EAAA;AAAA,IAC7D;AAAA,EAAA,GAEFjB,EAAQ,OAAO,4CAA4C,OAClD;AAAA,IACL,WAAWR,EAAA;AAAA,IACX,aAAaC,EAAA;AAAA,EAAe,EAE/B,GACDO,EAAQ,OAAO,gCAAgC,MAAM;AACnD,IAAAL,EAAA,GACAD,EAAA;AAAA,EACF,CAAC;AACH;"}
1
+ {"version":3,"file":"index.es.js","sources":["../src/storage.ts","../src/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Store from \"electron-store\";\n\nconst tokenTypeKey = \"tokenType\";\n\nconst accessTokenKey = \"accessToken\";\n\ntype StoreType = {\n tokenType: string;\n accessToken: string;\n};\n\nconst schema = {\n tokenType: {\n type: \"string\",\n },\n\n accessToken: {\n type: \"string\",\n },\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"authentication-github-main\",\n schema,\n // TODO: add encryption key\n});\n\nfunction setTokenType(value: string): void {\n storeInstance.set(tokenTypeKey, value);\n}\n\nfunction setAccessToken(value: string): void {\n storeInstance.set(accessTokenKey, value);\n}\n\nfunction getTokenType(): string {\n return storeInstance.get(tokenTypeKey);\n}\n\nfunction getAccessToken(): string {\n return storeInstance.get(accessTokenKey);\n}\n\nfunction deleteTokenType(): void {\n storeInstance.delete(tokenTypeKey);\n}\n\nfunction deleteAccessToken(): void {\n storeInstance.delete(accessTokenKey);\n}\n\nexport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n};\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n} from \"./storage.js\";\nimport axios from \"axios\";\nimport { BrowserWindow, ipcMain } from \"electron\";\nimport type { UserDetails } from \"@xwiki/platform-authentication-api\";\n\nfunction getAuthorizationValue() {\n return `${getTokenType()} ${getAccessToken()}`;\n}\n\n/**\n * @param browserWindow - the browser window to use for the authentication process\n * @param reload - the reload function\n *\n * @since 0.15\n * @beta\n */\nexport function load(\n browserWindow: BrowserWindow,\n reload: (win: BrowserWindow) => void,\n): void {\n ipcMain.handle(\n \"authentication:github:login\",\n async (\n _event,\n {\n baseUrl,\n deviceCode,\n interval,\n expiresIn,\n }: {\n baseUrl: string;\n deviceCode: string;\n interval: string;\n expiresIn: string;\n },\n ) => {\n const verificationUrl = new URL(`${baseUrl}/device-verify`);\n verificationUrl.searchParams.set(\"device_code\", deviceCode);\n\n // This converts the interval polling time and expiration time provided by\n // GitHub to milliseconds.\n // We need to add a little more delay to the interval when polling, just to\n // be sure that we don't go to fast for GitHub (or we might get rate\n // limited).\n const intervalMs: number = parseInt(interval) * 1000 + 500;\n let expiresInMs: number = parseInt(expiresIn) * 1000;\n\n // This interval handles polling the backend for the access token, using\n // the interval time computed earlier.\n // The backend will return an error until the login process has succeeded.\n const intervalId = setInterval(async () => {\n const response = await fetch(verificationUrl);\n const jsonResponse: {\n error?: string;\n access_token?: string;\n token_type?: string;\n } = await response.json();\n if (!jsonResponse.error) {\n setAccessToken(jsonResponse.access_token!);\n setTokenType(jsonResponse.token_type!);\n clearInterval(intervalId);\n // We reload the content on successful login.\n reload(browserWindow);\n } else if (expiresInMs <= 0) {\n clearInterval(intervalId);\n }\n expiresInMs -= intervalMs;\n }, intervalMs);\n },\n );\n\n ipcMain.handle(\"authentication:github:isLoggedIn\", () => {\n const tokenType = getTokenType();\n const accessTokenKey = getAccessToken();\n return tokenType && accessTokenKey;\n });\n\n ipcMain.handle(\n \"authentication:github:userDetails\",\n async (): Promise<UserDetails> => {\n const userinfoUrl = \"https://api.github.com/user\";\n const data = {\n headers: {\n Authorization: getAuthorizationValue(),\n },\n };\n const {\n data: { login, html_url, name, avatar_url },\n } = await axios.get(userinfoUrl, data);\n\n return { profile: html_url, username: login, name, avatar: avatar_url };\n },\n );\n ipcMain.handle(\"authentication:github:authorizationValue\", () => {\n return {\n tokenType: getTokenType(),\n accessToken: getAccessToken(),\n };\n });\n ipcMain.handle(\"authentication:github:logout\", () => {\n deleteAccessToken();\n deleteTokenType();\n });\n}\n"],"names":["tokenTypeKey","accessTokenKey","schema","storeInstance","Store","setTokenType","value","setAccessToken","getTokenType","getAccessToken","deleteTokenType","deleteAccessToken","getAuthorizationValue","load","browserWindow","reload","ipcMain","_event","baseUrl","deviceCode","interval","expiresIn","verificationUrl","intervalMs","expiresInMs","intervalId","jsonResponse","tokenType","userinfoUrl","data","login","html_url","name","avatar_url","axios"],"mappings":";;;AAsBA,MAAMA,IAAe,aAEfC,IAAiB,eAOjBC,IAAS;AAAA,EACb,WAAW;AAAA,IACT,MAAM;AAAA,EAAA;AAAA,EAGR,aAAa;AAAA,IACX,MAAM;AAAA,EAAA;AAEV,GAEMC,IAAkC,IAAIC,EAAiB;AAAA,EAC3D,MAAM;AAAA,EACN,QAAAF;AAAA;AAEF,CAAC;AAED,SAASG,EAAaC,GAAqB;AACzC,EAAAH,EAAc,IAAIH,GAAcM,CAAK;AACvC;AAEA,SAASC,EAAeD,GAAqB;AAC3C,EAAAH,EAAc,IAAIF,GAAgBK,CAAK;AACzC;AAEA,SAASE,IAAuB;AAC9B,SAAOL,EAAc,IAAIH,CAAY;AACvC;AAEA,SAASS,IAAyB;AAChC,SAAON,EAAc,IAAIF,CAAc;AACzC;AAEA,SAASS,IAAwB;AAC/B,EAAAP,EAAc,OAAOH,CAAY;AACnC;AAEA,SAASW,IAA0B;AACjC,EAAAR,EAAc,OAAOF,CAAc;AACrC;ACrCA,SAASW,IAAwB;AAC/B,SAAO,GAAGJ,EAAA,CAAc,IAAIC,GAAgB;AAC9C;AASO,SAASI,EACdC,GACAC,GACM;AACN,EAAAC,EAAQ;AAAA,IACN;AAAA,IACA,OACEC,GACA;AAAA,MACE,SAAAC;AAAA,MACA,YAAAC;AAAA,MACA,UAAAC;AAAA,MACA,WAAAC;AAAA,IAAA,MAOC;AACH,YAAMC,IAAkB,IAAI,IAAI,GAAGJ,CAAO,gBAAgB;AAC1D,MAAAI,EAAgB,aAAa,IAAI,eAAeH,CAAU;AAO1D,YAAMI,IAAqB,SAASH,CAAQ,IAAI,MAAO;AACvD,UAAII,IAAsB,SAASH,CAAS,IAAI;AAKhD,YAAMI,IAAa,YAAY,YAAY;AAEzC,cAAMC,IAIF,OALa,MAAM,MAAMJ,CAAe,GAKzB,KAAA;AACnB,QAAKI,EAAa,QAMPF,KAAe,KACxB,cAAcC,CAAU,KANxBlB,EAAemB,EAAa,YAAa,GACzCrB,EAAaqB,EAAa,UAAW,GACrC,cAAcD,CAAU,GAExBV,EAAOD,CAAa,IAItBU,KAAeD;AAAA,MACjB,GAAGA,CAAU;AAAA,IACf;AAAA,EAAA,GAGFP,EAAQ,OAAO,oCAAoC,MAAM;AACvD,UAAMW,IAAYnB,EAAA,GACZP,IAAiBQ,EAAA;AACvB,WAAOkB,KAAa1B;AAAA,EACtB,CAAC,GAEDe,EAAQ;AAAA,IACN;AAAA,IACA,YAAkC;AAChC,YAAMY,IAAc,+BACdC,IAAO;AAAA,QACX,SAAS;AAAA,UACP,eAAejB,EAAA;AAAA,QAAsB;AAAA,MACvC,GAEI;AAAA,QACJ,MAAM,EAAE,OAAAkB,GAAO,UAAAC,GAAU,MAAAC,GAAM,YAAAC,EAAA;AAAA,MAAW,IACxC,MAAMC,EAAM,IAAIN,GAAaC,CAAI;AAErC,aAAO,EAAE,SAASE,GAAU,UAAUD,GAAO,MAAAE,GAAM,QAAQC,EAAA;AAAA,IAC7D;AAAA,EAAA,GAEFjB,EAAQ,OAAO,4CAA4C,OAClD;AAAA,IACL,WAAWR,EAAA;AAAA,IACX,aAAaC,EAAA;AAAA,EAAe,EAE/B,GACDO,EAAQ,OAAO,gCAAgC,MAAM;AACnD,IAAAL,EAAA,GACAD,EAAA;AAAA,EACF,CAAC;AACH;"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.umd.js","sources":["../src/storage.ts","../src/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Store from \"electron-store\";\n\nconst tokenTypeKey = \"tokenType\";\n\nconst accessTokenKey = \"accessToken\";\n\ntype StoreType = {\n tokenType: string;\n accessToken: string;\n};\n\nconst schema = {\n tokenType: {\n type: \"string\",\n },\n\n accessToken: {\n type: \"string\",\n },\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"authentication-github-main\",\n schema,\n // TODO: add encryption key\n});\n\nfunction setTokenType(value: string): void {\n storeInstance.set(tokenTypeKey, value);\n}\n\nfunction setAccessToken(value: string): void {\n storeInstance.set(accessTokenKey, value);\n}\n\nfunction getTokenType(): string {\n return storeInstance.get(tokenTypeKey);\n}\n\nfunction getAccessToken(): string {\n return storeInstance.get(accessTokenKey);\n}\n\nfunction deleteTokenType(): void {\n storeInstance.delete(tokenTypeKey);\n}\n\nfunction deleteAccessToken(): void {\n storeInstance.delete(accessTokenKey);\n}\n\nexport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n};\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n} from \"./storage.js\";\nimport axios from \"axios\";\nimport { BrowserWindow, ipcMain } from \"electron\";\nimport type { UserDetails } from \"@xwiki/cristal-authentication-api\";\n\nfunction getAuthorizationValue() {\n return `${getTokenType()} ${getAccessToken()}`;\n}\n\n/**\n * @param browserWindow - the browser window to use for the authentication process\n * @param reload - the reload function\n *\n * @since 0.15\n * @beta\n */\nexport function load(\n browserWindow: BrowserWindow,\n reload: (win: BrowserWindow) => void,\n): void {\n ipcMain.handle(\n \"authentication:github:login\",\n async (\n _event,\n {\n baseUrl,\n deviceCode,\n interval,\n expiresIn,\n }: {\n baseUrl: string;\n deviceCode: string;\n interval: string;\n expiresIn: string;\n },\n ) => {\n const verificationUrl = new URL(`${baseUrl}/device-verify`);\n verificationUrl.searchParams.set(\"device_code\", deviceCode);\n\n // This converts the interval polling time and expiration time provided by\n // GitHub to milliseconds.\n // We need to add a little more delay to the interval when polling, just to\n // be sure that we don't go to fast for GitHub (or we might get rate\n // limited).\n const intervalMs: number = parseInt(interval) * 1000 + 500;\n let expiresInMs: number = parseInt(expiresIn) * 1000;\n\n // This interval handles polling the backend for the access token, using\n // the interval time computed earlier.\n // The backend will return an error until the login process has succeeded.\n const intervalId = setInterval(async () => {\n const response = await fetch(verificationUrl);\n const jsonResponse: {\n error?: string;\n access_token?: string;\n token_type?: string;\n } = await response.json();\n if (!jsonResponse.error) {\n setAccessToken(jsonResponse.access_token!);\n setTokenType(jsonResponse.token_type!);\n clearInterval(intervalId);\n // We reload the content on successful login.\n reload(browserWindow);\n } else if (expiresInMs <= 0) {\n clearInterval(intervalId);\n }\n expiresInMs -= intervalMs;\n }, intervalMs);\n },\n );\n\n ipcMain.handle(\"authentication:github:isLoggedIn\", () => {\n const tokenType = getTokenType();\n const accessTokenKey = getAccessToken();\n return tokenType && accessTokenKey;\n });\n\n ipcMain.handle(\n \"authentication:github:userDetails\",\n async (): Promise<UserDetails> => {\n const userinfoUrl = \"https://api.github.com/user\";\n const data = {\n headers: {\n Authorization: getAuthorizationValue(),\n },\n };\n const {\n data: { login, html_url, name, avatar_url },\n } = await axios.get(userinfoUrl, data);\n\n return { profile: html_url, username: login, name, avatar: avatar_url };\n },\n );\n ipcMain.handle(\"authentication:github:authorizationValue\", () => {\n return {\n tokenType: getTokenType(),\n accessToken: getAccessToken(),\n };\n });\n ipcMain.handle(\"authentication:github:logout\", () => {\n deleteAccessToken();\n deleteTokenType();\n });\n}\n"],"names":["tokenTypeKey","accessTokenKey","schema","storeInstance","Store","setTokenType","value","setAccessToken","getTokenType","getAccessToken","deleteTokenType","deleteAccessToken","getAuthorizationValue","load","browserWindow","reload","ipcMain","_event","baseUrl","deviceCode","interval","expiresIn","verificationUrl","intervalMs","expiresInMs","intervalId","jsonResponse","tokenType","userinfoUrl","data","login","html_url","name","avatar_url","axios"],"mappings":"kYAsBA,MAAMA,EAAe,YAEfC,EAAiB,cAOjBC,EAAS,CACb,UAAW,CACT,KAAM,QAAA,EAGR,YAAa,CACX,KAAM,QAAA,CAEV,EAEMC,EAAkC,IAAIC,EAAiB,CAC3D,KAAM,6BACN,OAAAF,CAEF,CAAC,EAED,SAASG,EAAaC,EAAqB,CACzCH,EAAc,IAAIH,EAAcM,CAAK,CACvC,CAEA,SAASC,EAAeD,EAAqB,CAC3CH,EAAc,IAAIF,EAAgBK,CAAK,CACzC,CAEA,SAASE,GAAuB,CAC9B,OAAOL,EAAc,IAAIH,CAAY,CACvC,CAEA,SAASS,GAAyB,CAChC,OAAON,EAAc,IAAIF,CAAc,CACzC,CAEA,SAASS,GAAwB,CAC/BP,EAAc,OAAOH,CAAY,CACnC,CAEA,SAASW,GAA0B,CACjCR,EAAc,OAAOF,CAAc,CACrC,CCrCA,SAASW,GAAwB,CA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C,CACH"}
1
+ {"version":3,"file":"index.umd.js","sources":["../src/storage.ts","../src/index.ts"],"sourcesContent":["/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport Store from \"electron-store\";\n\nconst tokenTypeKey = \"tokenType\";\n\nconst accessTokenKey = \"accessToken\";\n\ntype StoreType = {\n tokenType: string;\n accessToken: string;\n};\n\nconst schema = {\n tokenType: {\n type: \"string\",\n },\n\n accessToken: {\n type: \"string\",\n },\n};\n\nconst storeInstance: Store<StoreType> = new Store<StoreType>({\n name: \"authentication-github-main\",\n schema,\n // TODO: add encryption key\n});\n\nfunction setTokenType(value: string): void {\n storeInstance.set(tokenTypeKey, value);\n}\n\nfunction setAccessToken(value: string): void {\n storeInstance.set(accessTokenKey, value);\n}\n\nfunction getTokenType(): string {\n return storeInstance.get(tokenTypeKey);\n}\n\nfunction getAccessToken(): string {\n return storeInstance.get(accessTokenKey);\n}\n\nfunction deleteTokenType(): void {\n storeInstance.delete(tokenTypeKey);\n}\n\nfunction deleteAccessToken(): void {\n storeInstance.delete(accessTokenKey);\n}\n\nexport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n};\n","/**\n * See the LICENSE file distributed with this work for additional\n * information regarding copyright ownership.\n *\n * This is free software; you can redistribute it and/or modify it\n * under the terms of the GNU Lesser General Public License as\n * published by the Free Software Foundation; either version 2.1 of\n * the License, or (at your option) any later version.\n *\n * This software is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\n * Lesser General Public License for more details.\n *\n * You should have received a copy of the GNU Lesser General Public\n * License along with this software; if not, write to the Free\n * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA\n * 02110-1301 USA, or see the FSF site: http://www.fsf.org.\n */\n\nimport {\n deleteAccessToken,\n deleteTokenType,\n getAccessToken,\n getTokenType,\n setAccessToken,\n setTokenType,\n} from \"./storage.js\";\nimport axios from \"axios\";\nimport { BrowserWindow, ipcMain } from \"electron\";\nimport type { UserDetails } from \"@xwiki/platform-authentication-api\";\n\nfunction getAuthorizationValue() {\n return `${getTokenType()} ${getAccessToken()}`;\n}\n\n/**\n * @param browserWindow - the browser window to use for the authentication process\n * @param reload - the reload function\n *\n * @since 0.15\n * @beta\n */\nexport function load(\n browserWindow: BrowserWindow,\n reload: (win: BrowserWindow) => void,\n): void {\n ipcMain.handle(\n \"authentication:github:login\",\n async (\n _event,\n {\n baseUrl,\n deviceCode,\n interval,\n expiresIn,\n }: {\n baseUrl: string;\n deviceCode: string;\n interval: string;\n expiresIn: string;\n },\n ) => {\n const verificationUrl = new URL(`${baseUrl}/device-verify`);\n verificationUrl.searchParams.set(\"device_code\", deviceCode);\n\n // This converts the interval polling time and expiration time provided by\n // GitHub to milliseconds.\n // We need to add a little more delay to the interval when polling, just to\n // be sure that we don't go to fast for GitHub (or we might get rate\n // limited).\n const intervalMs: number = parseInt(interval) * 1000 + 500;\n let expiresInMs: number = parseInt(expiresIn) * 1000;\n\n // This interval handles polling the backend for the access token, using\n // the interval time computed earlier.\n // The backend will return an error until the login process has succeeded.\n const intervalId = setInterval(async () => {\n const response = await fetch(verificationUrl);\n const jsonResponse: {\n error?: string;\n access_token?: string;\n token_type?: string;\n } = await response.json();\n if (!jsonResponse.error) {\n setAccessToken(jsonResponse.access_token!);\n setTokenType(jsonResponse.token_type!);\n clearInterval(intervalId);\n // We reload the content on successful login.\n reload(browserWindow);\n } else if (expiresInMs <= 0) {\n clearInterval(intervalId);\n }\n expiresInMs -= intervalMs;\n }, intervalMs);\n },\n );\n\n ipcMain.handle(\"authentication:github:isLoggedIn\", () => {\n const tokenType = getTokenType();\n const accessTokenKey = getAccessToken();\n return tokenType && accessTokenKey;\n });\n\n ipcMain.handle(\n \"authentication:github:userDetails\",\n async (): Promise<UserDetails> => {\n const userinfoUrl = \"https://api.github.com/user\";\n const data = {\n headers: {\n Authorization: getAuthorizationValue(),\n },\n };\n const {\n data: { login, html_url, name, avatar_url },\n } = await axios.get(userinfoUrl, data);\n\n return { profile: html_url, username: login, name, avatar: avatar_url };\n },\n );\n ipcMain.handle(\"authentication:github:authorizationValue\", () => {\n return {\n tokenType: getTokenType(),\n accessToken: getAccessToken(),\n };\n });\n ipcMain.handle(\"authentication:github:logout\", () => {\n deleteAccessToken();\n deleteTokenType();\n });\n}\n"],"names":["tokenTypeKey","accessTokenKey","schema","storeInstance","Store","setTokenType","value","setAccessToken","getTokenType","getAccessToken","deleteTokenType","deleteAccessToken","getAuthorizationValue","load","browserWindow","reload","ipcMain","_event","baseUrl","deviceCode","interval","expiresIn","verificationUrl","intervalMs","expiresInMs","intervalId","jsonResponse","tokenType","userinfoUrl","data","login","html_url","name","avatar_url","axios"],"mappings":"kYAsBA,MAAMA,EAAe,YAEfC,EAAiB,cAOjBC,EAAS,CACb,UAAW,CACT,KAAM,QAAA,EAGR,YAAa,CACX,KAAM,QAAA,CAEV,EAEMC,EAAkC,IAAIC,EAAiB,CAC3D,KAAM,6BACN,OAAAF,CAEF,CAAC,EAED,SAASG,EAAaC,EAAqB,CACzCH,EAAc,IAAIH,EAAcM,CAAK,CACvC,CAEA,SAASC,EAAeD,EAAqB,CAC3CH,EAAc,IAAIF,EAAgBK,CAAK,CACzC,CAEA,SAASE,GAAuB,CAC9B,OAAOL,EAAc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AAUD,EAAO,KAAAE,EAAM,OAAQC,CAAA,CAC7D,CAAA,EAEFjB,UAAQ,OAAO,2CAA4C,KAClD,CACL,UAAWR,EAAA,EACX,YAAaC,EAAA,CAAe,EAE/B,EACDO,UAAQ,OAAO,+BAAgC,IAAM,CACnDL,EAAA,EACAD,EAAA,CACF,CAAC,CACH"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xwiki/cristal-electron-authentication-github-main",
3
- "version": "0.24.0",
3
+ "version": "0.25.0",
4
4
  "license": "LGPL 2.1",
5
5
  "author": "XWiki Org Community <contact@xwiki.org>",
6
6
  "homepage": "https://cristal.xwiki.org/",
@@ -28,17 +28,17 @@
28
28
  "main": "./dist/index.es.js",
29
29
  "types": "./dist/index.d.ts",
30
30
  "dependencies": {
31
- "axios": "1.13.1",
32
- "electron-store": "11.0.2",
33
- "@xwiki/cristal-authentication-api": "0.24.0"
31
+ "@xwiki/platform-authentication-api": "18.0.0-1766398944",
32
+ "axios": "1.13.2",
33
+ "electron-store": "11.0.2"
34
34
  },
35
35
  "peerDependencies": {
36
- "electron": "39.0.0"
36
+ "electron": "39.2.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "typescript": "5.9.3",
40
- "vite": "7.1.12",
41
- "@xwiki/cristal-dev-config": "0.24.0"
40
+ "vite": "7.2.7",
41
+ "@xwiki/cristal-dev-config": "0.25.0"
42
42
  },
43
43
  "scripts": {
44
44
  "api-extractor:local": "api-extractor run --local",
package/src/index.ts CHANGED
@@ -28,7 +28,7 @@ import {
28
28
  } from "./storage.js";
29
29
  import axios from "axios";
30
30
  import { BrowserWindow, ipcMain } from "electron";
31
- import type { UserDetails } from "@xwiki/cristal-authentication-api";
31
+ import type { UserDetails } from "@xwiki/platform-authentication-api";
32
32
 
33
33
  function getAuthorizationValue() {
34
34
  return `${getTokenType()} ${getAccessToken()}`;
package/CHANGELOG.md DELETED
@@ -1,111 +0,0 @@
1
- # @xwiki/cristal-electron-authentication-github-main
2
-
3
- ## 0.23.0
4
-
5
- ### Minor Changes
6
-
7
- - Cristal 0.23 Release
8
-
9
- ### Patch Changes
10
-
11
- - Updated dependencies
12
- - @xwiki/cristal-authentication-api@0.23.0
13
-
14
- ## 0.22.0
15
-
16
- ### Minor Changes
17
-
18
- - Cristal 0.22 Release
19
-
20
- ### Patch Changes
21
-
22
- - Updated dependencies
23
- - @xwiki/cristal-authentication-api@0.22.0
24
-
25
- ## 0.21.0
26
-
27
- ### Minor Changes
28
-
29
- - Cristal 0.21 Release
30
-
31
- ### Patch Changes
32
-
33
- - Updated dependencies
34
- - @xwiki/cristal-authentication-api@0.21.0
35
-
36
- ## 0.20.0
37
-
38
- ### Minor Changes
39
-
40
- - Cristal 0.20 Release
41
-
42
- ### Patch Changes
43
-
44
- - Updated dependencies
45
- - @xwiki/cristal-authentication-api@0.20.0
46
-
47
- ## 0.20.0-rc.0
48
-
49
- ### Minor Changes
50
-
51
- - Cristal 0.20-rc-1 Release
52
-
53
- ### Patch Changes
54
-
55
- - Updated dependencies
56
- - @xwiki/cristal-authentication-api@0.20.0-rc.0
57
-
58
- ## 0.19.0
59
-
60
- ### Minor Changes
61
-
62
- - 3eea53e: Cristal 0.19 Release
63
-
64
- ### Patch Changes
65
-
66
- - Updated dependencies [3eea53e]
67
- - @xwiki/cristal-authentication-api@0.19.0
68
-
69
- ## 0.18.0
70
-
71
- ### Minor Changes
72
-
73
- - Cristal 0.18 Release
74
-
75
- ### Patch Changes
76
-
77
- - Updated dependencies
78
- - @xwiki/cristal-authentication-api@0.18.0
79
-
80
- ## 0.17.0
81
-
82
- ### Minor Changes
83
-
84
- - Cristal 0.17 Release
85
-
86
- ### Patch Changes
87
-
88
- - Updated dependencies
89
- - @xwiki/cristal-authentication-api@0.17.0
90
-
91
- ## 0.16.0
92
-
93
- ### Minor Changes
94
-
95
- - Cristal 0.16 Release
96
-
97
- ### Patch Changes
98
-
99
- - Updated dependencies
100
- - @xwiki/cristal-authentication-api@0.16.0
101
-
102
- ## 0.15.0
103
-
104
- ### Minor Changes
105
-
106
- - Cristal 0.15 Release
107
-
108
- ### Patch Changes
109
-
110
- - Updated dependencies
111
- - @xwiki/cristal-authentication-api@0.15.0