New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

tucmc-auth

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tucmc-auth - npm Package Compare versions

Comparing version 0.1.1 to 0.1.2

7

CHANGELOG.md

@@ -68,1 +68,8 @@ # Changelog

- Check client token before sending any request to server
- playground folder for examples
## [0.1.2] - 2020-08-21
## Fixed
- Reimplemented client token validating system.

5

dist/index.es.js
import React, { useContext, useState, useEffect } from 'react';
import FingerprintJS from '@fingerprintjs/fingerprintjs';
import * as crypto from 'crypto';

@@ -371,5 +370,3 @@ /*! *****************************************************************************

var checkToken = function () {
var hostname = window.location.origin;
var hashed = crypto.createHash("SHA256").update(hostname).digest("base64");
return token.includes(hashed);
return token.length === 44;
};

@@ -376,0 +373,0 @@

21

dist/script/auth-lib.js

@@ -71,24 +71,11 @@ function init() {

async _checkToken() {
const hostname = window.location.origin
const arrayBuffer = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(hostname))
function _arrayBufferToBase64( buffer ) {
let binary = ''
let bytes = new Uint8Array( buffer )
let len = bytes.byteLength
for (let i = 0; i < len; i++) {
binary += String.fromCharCode( bytes[ i ] )
}
return window.btoa( binary )
}
return this.TOKEN.includes(_arrayBufferToBase64(arrayBuffer))
_checkToken() {
return this.TOKEN.length === 44
}
async signin() {
signin() {
const data = window.localStorage.getItem("data")
if (data) return
if (this.prevPop) this.prevPop.close()
if (!await this._checkToken()) {console.log("invalid_client_token"); return;}
if (!this._checkToken()) {console.log("invalid_client_token"); return;}

@@ -95,0 +82,0 @@ this._setLoading()

@@ -1,1 +0,1 @@

function init(){const fp=FingerprintJS.load();fp.then(fp=>fp.get()).then(result=>{window.fingerPrint=result.visitorId})}class TUCMCAuth{constructor(TOKEN){this.TOKEN=TOKEN;this.prevPop=null;window.addEventListener("load",()=>{document.getElementById("login_with_TUCMC").addEventListener("click",()=>{this.signin()})})}signout(){window.localStorage.setItem("data","");window.location.reload()}_setLoading(){document.getElementById("login_with_TUCMC").innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; shape-rendering: auto;width: 40px; height: 26px" viewBox="0 0 100 80" preserveAspectRatio="xMidYMid">\n'+' <circle cx="84" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="0.7142857142857142s" calcMode="spline" keyTimes="0;1" values="10;0"\n'+' keySplines="0 0.5 0.5 1" begin="0s"/>\n'+' <animate attributeName="fill" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="discrete" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="#ffffff;#ffffff;#ffffff;#ffffff;#ffffff" begin="0s"/>\n'+" </circle>\n"+' <circle cx="16" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="0s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="0s"/>\n'+" </circle>\n"+' <circle cx="50" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-0.7142857142857142s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-0.7142857142857142s"/>\n'+" </circle>\n"+' <circle cx="84" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-1.4285714285714284s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-1.4285714285714284s"/>\n'+" </circle>\n"+' <circle cx="16" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-2.142857142857143s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-2.142857142857143s"/>\n'+" </circle>\n"+" </svg>";document.getElementById("login_with_TUCMC").style.padding="0.15rem 4.71rem";setTimeout(()=>{this._resetLoading()},3*60*1e3)}_resetLoading(){document.getElementById("login_with_TUCMC").innerHTML="Login with TUCMC";document.getElementById("login_with_TUCMC").style.padding="0.5rem 2rem"}async _checkToken(){const hostname=window.location.origin;const arrayBuffer=await crypto.subtle.digest("SHA-256",(new TextEncoder).encode(hostname));function _arrayBufferToBase64(buffer){let binary="";let bytes=new Uint8Array(buffer);let len=bytes.byteLength;for(let i=0;i<len;i++){binary+=String.fromCharCode(bytes[i])}return window.btoa(binary)}return this.TOKEN.includes(_arrayBufferToBase64(arrayBuffer))}async signin(){const data=window.localStorage.getItem("data");if(data)return;if(this.prevPop)this.prevPop.close();if(!await this._checkToken()){console.log("invalid_client_token");return}this._setLoading();const wid=window.open("https://account.triamudom.club/auth","_blank","width=492,height=740");this.prevPop=wid;async function _fetchToken(token,resetLoading){const res=await fetch(`https://account.triamudom.club/api/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"fetchAuthToken",authToken:window.sessionStorage.getItem("authToken"),reqToken:token,fp:fingerPrint})});const jsonResult=await res.json();if(jsonResult.status){window.sessionStorage.setItem("authToken","");window.localStorage.setItem("data",JSON.stringify(jsonResult.data.data));window.location.reload()}resetLoading()}const inter=setInterval(()=>{if(this.prevPop.closed){_fetchToken(this.TOKEN,this._resetLoading);clearInterval(inter)}},500);async function _genToken(token){const res=await fetch(`https://account.triamudom.club/api/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"genAuthToken",reqToken:token,fp:fingerPrint})});return await res.json()}_genToken(this.TOKEN).then(jsonResult=>{if(jsonResult.status){window.sessionStorage.setItem("authToken",jsonResult.data.authToken);wid.location.replace(`https://account.triamudom.club/auth?authToken=${jsonResult.data.authToken}`)}})}user(){const data=window.localStorage.getItem("data");if(data){const parsed=JSON.parse(data);return parsed.data}else{return null}}}
function init(){const fp=FingerprintJS.load();fp.then(fp=>fp.get()).then(result=>{window.fingerPrint=result.visitorId})}class TUCMCAuth{constructor(TOKEN){this.TOKEN=TOKEN;this.prevPop=null;window.addEventListener("load",()=>{document.getElementById("login_with_TUCMC").addEventListener("click",()=>{this.signin()})})}signout(){window.localStorage.setItem("data","");window.location.reload()}_setLoading(){document.getElementById("login_with_TUCMC").innerHTML='<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="margin: auto; shape-rendering: auto;width: 40px; height: 26px" viewBox="0 0 100 80" preserveAspectRatio="xMidYMid">\n'+' <circle cx="84" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="0.7142857142857142s" calcMode="spline" keyTimes="0;1" values="10;0"\n'+' keySplines="0 0.5 0.5 1" begin="0s"/>\n'+' <animate attributeName="fill" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="discrete" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="#ffffff;#ffffff;#ffffff;#ffffff;#ffffff" begin="0s"/>\n'+" </circle>\n"+' <circle cx="16" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="0s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="0s"/>\n'+" </circle>\n"+' <circle cx="50" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-0.7142857142857142s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-0.7142857142857142s"/>\n'+" </circle>\n"+' <circle cx="84" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-1.4285714285714284s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-1.4285714285714284s"/>\n'+" </circle>\n"+' <circle cx="16" cy="50" r="10" fill="#ffffff">\n'+' <animate attributeName="r" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="0;0;10;10;10" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-2.142857142857143s"/>\n'+' <animate attributeName="cx" repeatCount="indefinite" dur="2.8571428571428568s" calcMode="spline" keyTimes="0;0.25;0.5;0.75;1"\n'+' values="16;16;16;50;84" keySplines="0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1;0 0.5 0.5 1" begin="-2.142857142857143s"/>\n'+" </circle>\n"+" </svg>";document.getElementById("login_with_TUCMC").style.padding="0.15rem 4.71rem";setTimeout(()=>{this._resetLoading()},3*60*1e3)}_resetLoading(){document.getElementById("login_with_TUCMC").innerHTML="Login with TUCMC";document.getElementById("login_with_TUCMC").style.padding="0.5rem 2rem"}_checkToken(){return this.TOKEN.length===44}signin(){const data=window.localStorage.getItem("data");if(data)return;if(this.prevPop)this.prevPop.close();if(!this._checkToken()){console.log("invalid_client_token");return}this._setLoading();const wid=window.open("https://account.triamudom.club/auth","_blank","width=492,height=740");this.prevPop=wid;async function _fetchToken(token,resetLoading){const res=await fetch(`https://account.triamudom.club/api/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"fetchAuthToken",authToken:window.sessionStorage.getItem("authToken"),reqToken:token,fp:fingerPrint})});const jsonResult=await res.json();if(jsonResult.status){window.sessionStorage.setItem("authToken","");window.localStorage.setItem("data",JSON.stringify(jsonResult.data.data));window.location.reload()}resetLoading()}const inter=setInterval(()=>{if(this.prevPop.closed){_fetchToken(this.TOKEN,this._resetLoading);clearInterval(inter)}},500);async function _genToken(token){const res=await fetch(`https://account.triamudom.club/api/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:"genAuthToken",reqToken:token,fp:fingerPrint})});return await res.json()}_genToken(this.TOKEN).then(jsonResult=>{if(jsonResult.status){window.sessionStorage.setItem("authToken",jsonResult.data.authToken);wid.location.replace(`https://account.triamudom.club/auth?authToken=${jsonResult.data.authToken}`)}})}user(){const data=window.localStorage.getItem("data");if(data){const parsed=JSON.parse(data);return parsed.data}else{return null}}}
{
"name": "tucmc-auth",
"version": "0.1.1",
"version": "0.1.2",
"module": "dist/index.es.js",

@@ -5,0 +5,0 @@ "types": "dist/index.d.ts",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc