react-linkedin-login-openid
Version:
Here’s the revised README file with the integration details for `linkedin-auth-server-openid` added, while keeping the tables intact:
3 lines (2 loc) • 4.64 kB
JavaScript
import{jsx as e,jsxs as t}from"react/jsx-runtime";import{useState as n,useEffect as r}from"react";var o="https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcTaROHX6N-OXfq1meZ8m5dwvsn2Uf53ipO7FA&s";function i(e,t,n){var r="".concat("https://www.linkedin.com/oauth/v2/authorization","?response_type=code&client_id=").concat(e,"&&state=").concat(window.location.pathname,"&redirect_uri=").concat(function(e){if(e.startsWith("http"))return e;e.length>0&&"/"!=e.charAt(0)&&(e="/"+e);return window.location.origin+e}(t),"&scope=openid");if(null!=n)for(var o=0,i=n;o<i.length;o++){var c=i[o];r+="%20".concat(c)}else r+="%20profile%20email";return r}function c(t){var n=t.imgUrl,r=i(t.client_id,t.redirect_url,t.permissions);return e("div",{children:e("a",{href:r,children:e("img",{src:n||o,alt:"Login_Image",srcSet:o})})})}function s(e,t,n,r){return new(n||(n=Promise))((function(o,i){function c(e){try{a(r.next(e))}catch(e){i(e)}}function s(e){try{a(r.throw(e))}catch(e){i(e)}}function a(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(c,s)}a((r=r.apply(e,t||[])).next())}))}function a(e,t){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},c=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return c.next=s(0),c.throw=s(1),c.return=s(2),"function"==typeof Symbol&&(c[Symbol.iterator]=function(){return this}),c;function s(s){return function(a){return function(s){if(n)throw new TypeError("Generator is already executing.");for(;c&&(c=0,s[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&s[0]?r.return:s[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,s[1])).done)return o;switch(r=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return i.label++,{value:s[1],done:!1};case 5:i.label++,r=s[1],s=[0];continue;case 7:s=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){i=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){i.label=s[1];break}if(6===s[0]&&i.label<o[1]){i.label=o[1],o=s;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(s);break}o[2]&&i.ops.pop(),i.trys.pop();continue}s=t.call(e,i)}catch(e){s=[6,e],r=0}finally{n=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}function l(){var e=new URLSearchParams(window.location.search),t=e.get("state");if(e.get("error")||!e.get("code")){var n=e.get("error"),r=e.get("error_description");return console.error(n),console.error(r),{success:!1,error_status:n,error_description:r,state:t}}return{success:!0,code:e.get("code"),state:t}}"function"==typeof SuppressedError&&SuppressedError;function u(o){var i=o.successPath,c=o.postUrl,u=n(),d=u[0],f=u[1];function h(e,t){setTimeout((function(){f(e.error_description||t||"Internal Server Error."),setTimeout((function(){e.state&&window.location.assign(e.state)}),2e3)}),1e3)}return r((function(){var e=l();e.success&&e.code?function(e,t){return s(this,void 0,void 0,(function(){var n;return a(this,(function(r){switch(r.label){case 0:return t?[3,1]:(sessionStorage.setItem("code",e),[3,3]);case 1:return[4,fetch(t,{method:"POST",body:JSON.stringify({code:e})})];case 2:return n=r.sent(),localStorage.setItem("UserData",JSON.stringify(n)),[2,n];case 3:return[2]}}))}))}(e.code,c).then((function(e){console.log(e),setTimeout((function(){f("Login SuccessFull"),setTimeout((function(){window.location.assign(i)}),1e3)}),1e3)})).catch((function(t){sessionStorage.setItem("code",e.code||""),h(e,"Code is stored in session. Could not send it to server. postUrlRequired")})):h(e)})),t("div",{children:["Please wait You will be redirected soon"," ",d&&t("div",{className:"alert",children:[e("span",{className:"closebtn",onClick:function(){return f(null)},children:"×"}),d]})]})}!function(e,t){void 0===t&&(t={});var n=t.insertAt;if("undefined"!=typeof document){var r=document.head||document.getElementsByTagName("head")[0],o=document.createElement("style");o.type="text/css","top"===n&&r.firstChild?r.insertBefore(o,r.firstChild):r.appendChild(o),o.styleSheet?o.styleSheet.cssText=e:o.appendChild(document.createTextNode(e))}}(".alert {\r\n padding: 20px;\r\n background-color: #f45936; /* Red */\r\n color: white;\r\n margin-bottom: 15px;\r\n}\r\n\r\n/* The close button */\r\n.closebtn {\r\n margin-left: 15px;\r\n color: white;\r\n font-weight: bold;\r\n float: right;\r\n font-size: 22px;\r\n line-height: 20px;\r\n cursor: pointer;\r\n transition: 0.3s;\r\n}\r\n\r\n/* When moving the mouse over the close button */\r\n.closebtn:hover {\r\n color: black;\r\n}");export{c as LinkedinButton,u as LinkedinPage};
//# sourceMappingURL=index.mjs.map