Yehosef
Yehosef

Reputation: 18657

How do I know when a OIDC authentication redirect was sent?

I'm using Flask-OIDC and, as an example, I have a route:

@app.route('/')
@oidc.require_login
def home():
  print('hi there')

Inside my application code/routes I only know that the user is authenticated. How can I know when a user has been authenticated?

We are using Okta hosted authentication (I don't think anything in this flow is specific to Okta) so the user is redirected to the Okta site and then redirected to our site with a token when successfully authenticated on their side. From what I understand the flow is like this:

  1. user comes to route
  2. Flask-OIDC code checks the OIDC cookie if valid, skip to 6
  3. OIDC code redirects them to Okta (or some other OpenID provider)
  4. user authenticates successfully by the remote provider
  5. user is redirected to OIDC endpoint on our server and is validated
  6. user access calls the route code

I want to hook into step 5 so that I can run some code when the user is successfully authenticated. How do I do that?

Upvotes: 0

Views: 583

Answers (1)

Kavindu Dodanduwa
Kavindu Dodanduwa

Reputation: 13069

From Flask documentation,

accept_token(require_token=False, scopes_required=None, render_errors=True)

Use this to decorate view functions that should accept OAuth2 tokens, this will most likely apply to API functions.

Tokens are accepted as part of the query URL (access_token value) or a POST form value (access_token).

Once user has successfully complete the OIDC flow, you application receive the OIDC (OAuth 2.0 as stated document) tokens from OKta. For requirement of step 5, you need to tap into this response handling method.

p.s - Found a code snippet as a reference.

Upvotes: 1

Related Questions