Giter VIP home page Giter VIP logo

Comments (5)

0f-0b avatar 0f-0b commented on August 10, 2024

Try again with a new CSRF token. Does this still happen?

from luogu-api-docs.

pai233 avatar pai233 commented on August 10, 2024

@sjx233 Yes, it still. I got a new CSRF token, but it still returns 400 Bad Request.

And this is my code(JavaScript):

let loginStatus=await LG_API.post('/api/auth/userPassLogin',{username,password,captcha},{
				headers: {
					'X-CSRF-TOKEN': await getToken(),//Get the CSRF Token
					'Referer': 'https://www.luogu.com.cn/auth/login',
					'Sec-Fetch-Dest': 'empty',//Copied form the broswer header :)
					'Sec-Fetch-Mode': 'cors',
					'Sec-Fetch-Site': 'same-origin',
					'Origin': 'https://www.luogu.com.cn/',
					'X-Requested-With': 'XMLHttpRequest'
				},
				jar: jar
			}).catch(err=>{
				if(err.response)console.log(err.response.data,"error")
				console.log(err.request._header)
			})

from luogu-api-docs.

pai233 avatar pai233 commented on August 10, 2024

And this is the code of getToken() Function:

async function getToken() {
	let token=await LG_API.get('/',{jar: jar}).then(html=>{
		var Token_REG=new RegExp(/<meta name="csrf-token" content="(.*)">/);
		var execData=Token_REG.exec(html.data)
		return execData ? execData[1].trim():null
	})
	return token;
}

Is it anything wrong?

from luogu-api-docs.

0f-0b avatar 0f-0b commented on August 10, 2024

You might need to get a token from /auth/login instead for now.

async function getToken() {
  const html = await LG_API.get("/auth/login", { jar });
  const match = html.match(/<meta name="csrf-token" content="([^"]*)">/);
  return match?.[1];
}

Will update the docs later.

from luogu-api-docs.

pai233 avatar pai233 commented on August 10, 2024

@sjx233 Thanks.

from luogu-api-docs.

Related Issues (12)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.