sumad200 / My-Val-Store

Check your daily valorant store without having to open the game, clean UI with pitch-black theme, supports viewing daily store, featured bundle(s) and night market.
3 stars 1 forks source link

[Not issue] Help me please with auth #4

Open rudnik275 opened 2 days ago

rudnik275 commented 2 days ago

Hello, sumad200, I dont know how to contact with you so I write here. I try to do local project for personal usage to check what's new in my valorant shop and night market from my telegram bot. But I have error on auth, I use bun (or nodejs) for my app.

Here my code

  // Make the first request to obtain session cookies
  const step1Response = await fetch('https://auth.riotgames.com/api/v1/authorization', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({
      client_id: 'riot-client',
      code_challenge: '',
      code_challenge_method: '',
      acr_values: '',
      claims: '',
      nonce: '69420',
      redirect_uri: 'http://localhost/redirect',
      response_type: 'token id_token',
      scope: 'openid link ban lol_region',
    }),
  })

// Check the response status and cookies
  if (!step1Response.ok) {
    console.error('Step 1 failed:', await step1Response.text())
    return
  }

// Extract cookies from the response
  const setCookieHeader = step1Response.headers.get('set-cookie')
  if (!setCookieHeader) {
    console.error('No cookies received from Step 1')
    return
  }

// Prepare cookies for the second request
  const cookies = setCookieHeader.split(', ').map(cookie => cookie.split(';')[0]).join('; ')

// Make the second request using the cookies
  const step2Response = await fetch('https://auth.riotgames.com/api/v1/authorization', {
    method: 'PUT',
    headers: {
      'Content-Type': 'application/json',
      'Cookie': cookies,  // Pass cookies from Step 1
    },
    body: JSON.stringify({
      remember: true,
      type: 'auth',
      username: process.env.RIOT_USERNAME,
      password: process.env.RIOT_PASSWORD,
    }),
  })

  console.log(
    process.env.RIOT_USERNAME,
    process.env.RIOT_PASSWORD,
  )
  const step2Data = await step2Response.json()
  if (!step2Response.ok) {
    console.error('Step 2 failed:', step2Data)
  } else {
    console.log('Step 2 successful:', step2Data)
  }

}

test()

but server respond me 200, but with next response:

Step 2 successful: {
  type: "auth",
  error: "auth_failure",
  country: "ukr",
}

What I doing wrong?

sumad200 commented 7 hours ago

Hey @rudnik275, The auth endpoint request body has changed .I've switched to using a webview for authentication. So, I no longer update any auth endpoint related code in my app. You should check out these resources for the latest info.

Techrism's val api docs Valorant App developers discord - For support and info on breaking changes as they happen

I also suggest you try getting the auth flow right first using postman/insomnia before coding, Also you can take a look at this discord bot repo (in python) as it matches your use case more closely.

Edit: Found a js discord bot https://github.com/giorgi-o/SkinPeek/