# JS function to authenticate and trigger a function without redirection

**URL:** <https://devforum.okta.com/t/js-function-to-authenticate-and-trigger-a-function-without-redirection/25900>\
**Category:** OAuth/OIDC\
**Created:** [November 23, 2023, 9:12am UTC](https://devforum.okta.com/t/js-function-to-authenticate-and-trigger-a-function-without-redirection/25900 "2023-11-23T09:12:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GabrielB](https://avatars.discourse-cdn.com/v4/letter/g/9fc348/32.png) [@GabrielB](https://devforum.okta.com/u/GabrielB)\
**Post date:** [November 23, 2023, 9:12am UTC](https://devforum.okta.com/t/js-function-to-authenticate-and-trigger-a-function-without-redirection/25900/1 "2023-11-23T09:12:03Z")

</div>

I’ve got a custom Javascript app that sends PATCH and POST request to a REST API endpoint when the user clicks on an specific button. I need that, every time, user clicks that button, an Okta login dialog is prompted (preferably popping up but redirection is fine) and if authentication success then an ajax request is sent in the backend to that REST API endpoint. Session stays as is. There is no need to redirect. Despite having the user already authenticated, we want to establish an extra security check when that button is clicked and keep audit record.

Is there any example available or would you offer some guidance?

---

<div class="post-metadata">

**Author:** ![alisaduncan](https://sea1.discourse-cdn.com/oktadev/user_avatar/devforum.okta.com/alisaduncan/32/3429_2.png) [@alisaduncan](https://devforum.okta.com/u/alisaduncan)\
**Post date:** [November 29, 2023, 2:23pm UTC](https://devforum.okta.com/t/js-function-to-authenticate-and-trigger-a-function-without-redirection/25900/2 "2023-11-29T14:23:04Z")

</div>

Hi there @GabrielB !

Have you looked into step-up authentication? The idea is that while basic access with authentication is fine, sensitive resources/actions require extra authentication. Depending on your Okta authentication model, you may need to redirect. Redirecting to Okta is the most secure way to handle authentication.

Here’s some blog posts to learn more:

> **[Step-up Authentication in Modern Applications](https://developer.okta.com/blog/2023/03/08/step-up-auth)**
>
> Understand and apply the principles of step-up authentication

> **[Step-Up Authentication Examples With Okta](https://developer.okta.com/blog/2023/10/24/stepup-okta)**
>
> Understand Step Up Authentication in Okta's Workforce Identity Cloud

and one from Auth0

> **[What Is Step-Up Authentication? When To Use It Over MFA or Adaptive Auth?](https://auth0.com/blog/what-is-step-up-authentication-when-to-use-it/)**
>
> Understand what step-up authentication is, learn how to use step-up auth, see the benefits of it versus multi-factor and adaptive auth. S...

Cheers to stepping up security!
