# Help Needed: Integrating Okta Login in Flutter App Using WebView - Redirection Error and Authorization Code Handling

**URL:** <https://devforum.okta.com/t/help-needed-integrating-okta-login-in-flutter-app-using-webview-redirection-error-and-authorization-code-handling/29128>\
**Category:** OAuth/OIDC\
**Tags:** mobile\
**Created:** [July 2, 2024, 6:55am UTC](https://devforum.okta.com/t/help-needed-integrating-okta-login-in-flutter-app-using-webview-redirection-error-and-authorization-code-handling/29128 "2024-07-02T06:55:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![himmatsingh](https://avatars.discourse-cdn.com/v4/letter/h/cdc98d/32.png) [@himmatsingh](https://devforum.okta.com/u/himmatsingh)\
**Post date:** [July 2, 2024, 6:55am UTC](https://devforum.okta.com/t/help-needed-integrating-okta-login-in-flutter-app-using-webview-redirection-error-and-authorization-code-handling/29128/1 "2024-07-02T06:55:51Z")

</div>

Hi everyone,

I’m currently working on integrating Okta authentication in my Flutter app using a WebView. I’ve set up the WebView to open the following URL for the OAuth2 authorization:

Here is a brief summary of what I’ve done so far:

1. Created an Okta application and obtained the `client_id`.
2. Configured the redirect URI as `https://trial-8927900.okta.com%3A%2Fcallback`.
3. Set up the WebView in my Flutter app to load the authorization URL.

The WebView loads the Okta login page, and I’m successfully able to log in. However, when the redirection back to the app is supposed to happen using the specified redirect URI, I’m encountering an error. Below is the error I’m seeing:

code=\_pm9ucd|55ojUwquOQvOUOAZzTFuPNDfYRKBI  
5c67-47a1-ac7c-08d4bd049db6 could not be loaded

From the documentation, I understand that the code received in the redirect URL is the authorization code. My questions are:

1. How do I properly handle the redirection and capture the authorization code in my Flutter app?
2. Once I have the authorization code, how can I exchange it for an access token?

I’d appreciate any guidance or examples on how to:

1. Capture the authorization code from the redirect URI.
2. Make the appropriate request to exchange the authorization code for an access token.

Sorry for not able to put proper links and screenshots, since i am a new user and this forum doesnot allow to put links.

Thank you in advance for your help!

---

<div class="post-metadata">

**Author:** ![nikitag](https://avatars.discourse-cdn.com/v4/letter/n/ce7236/32.png) [@nikitag](https://devforum.okta.com/u/nikitag)\
**Post date:** [July 3, 2024, 4:30am UTC](https://devforum.okta.com/t/help-needed-integrating-okta-login-in-flutter-app-using-webview-redirection-error-and-authorization-code-handling/29128/2 "2024-07-03T04:30:05Z")

</div>

Hi there,  
You can refer to our documentation here: [https://developer.okta.com/docs/guides/configure-native-sso/main/#exchange-the-code-for-tokens](https://developer.okta.com/docs/guides/configure-native-sso/main/#exchange-the-code-for-tokens)  
hope this helps! If you have further questions, feel free to drop us a message!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/oktadev/original/1X/589c4c5f80de422d01f47cee7185a7fb8227835c.png) [@system](https://devforum.okta.com/u/system)\
**Post date:** [August 2, 2024, 4:30am UTC](https://devforum.okta.com/t/help-needed-integrating-okta-login-in-flutter-app-using-webview-redirection-error-and-authorization-code-handling/29128/3 "2024-08-02T04:30:25Z")

</div>

Closed on August 2, 2024, 4:30am UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
