Rayrun
← Back to Discord Forum

How to get Okta token in C# using API

Trying to get a token using Okta API using C#. Having issues building the request correctly.

This thread is trying to answer question "How to get a token using Okta API in C#?"

1 reply

Hi, I use auth setup for API login to OKTA but with JS. Nevertheless the main idea and structure of the request should be the same i believe

// Send authentication request.
setup('authenticate', async ({ request }) => {
const response = await request.post(authUrl, {
    data: {
      options: {
        multiOptionalFactorEnroll: true,
        warnBeforePasswordExpired: true
      },
      password: pass,
      username: user
    }
  })
  const token = await response.json()
  // auth with request playwright using cookies
const auth = await request.get(
    `https://<yourdomain>.okta.com/login/sessionCookieRedirect?token=${token.sessionToken}&redirectUrl=${redirectUrl}`
  )
  console.log(
    `***** Logged in as user: ${user} with status ${auth.status()}, ${auth.statusText()}, saving storage state *****`
  )

  await request.storageState({ path: authFile })
})
TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].