Okta not returning to the Xamarin Forms app

I am still working through authentication using Okta on my xamarin forms app. I believe I have am not using the correct Redirect URI in the OAuth2Authenticator constructor below. Although I appear able to enter my Okta credentials, I do not return to the mobile app. instead I sit on the Okta developer webpage (the Login_redirect_URIs) property below. I have tried changing it to another (random) website, and it makes no difference. When I press the back button, I receive a AuthenticatorCompletedEventArgs.IsAuthenticated == false result.

What should I be passing in for the Login_redirect_URIs value?

ClientID:
Client authentication: Use PKCE
Okta_domain: dev-xxxxxx.okta.com
Allowed_grant_types: Authorization Code
Login_redirect_URIs: com.okta.dev-xxxxxx:/callback
Logout_redirect_URIs: com.okta.dev-xxxxxx:/
Initiate_login_URI: com.okta.dev-xxxxxx:/callback

From my xamarin app loginViewModel.cs page I am using the above as follows;
Scopes = “openid, email”

var authenticator = new OAuth2Authenticator(ClientID,
Scopes,
new Uri(Okta_domain),
new Uri(Login_redirect_URIs),
null,
false);

var Presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
Presenter.Login(authenticator);
authenticator.Completed += OktaAuthenticator_Completed;

Hi @Lenny! For Android, you’ll need the IntentFilter. The DataScheme in the Android IntentFilter should match what you have registered in his Okta Dashboard.

[Activity(Label = "LoginCallbackInterceptorActivity", NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[
	IntentFilter
	(
		actions: new[] { Intent.ActionView }, 
		Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
		DataSchemes = new[] { "com.okta.xamarin.android.login" },
		DataPath = "/callback"
	)
]
public class LoginCallbackInterceptorActivity : Activity { }

For iOS, you’ll need to register the URIs as custom url types in your Info.plist. And then in your appdelegate implementation you’ll need to override the OpenUrl method to determine what to do with the callback when your users get redirected back to your app.


image (8)

Hi @Lenny

Did you get this working?
I have the exactly the same problem, the Okta login page appears, I login but it does not return to my app, but instead, redirects to my okta dashboard???

Here’s my viewmodel code…

string clientID = “xxxxxxxxxx”;
string scope = “openid,email”;
string oktaDomain = “https://dev-xxxxxxxx.okta.com”;
string redirectURL = “com.okta.dev-xxxxxxxx:/callback”;

var _authenticator = new OAuth2Authenticator(clientID,
scope,
new Uri(oktaDomain),
new Uri(redirectURL),
null,
false);

_authenticator.AllowCancel = true;
_authenticator.ShowErrors = true;

var _presenter = new OAuthLoginPresenter();
_presenter.Login(_authenticator);

_authenticator.Completed += _authenticator_Completed;

here’s my mainactivity.cs code…

[Activity(Label = “LoginCallbackInterceptorActivity”, NoHistory = true, LaunchMode = LaunchMode.SingleTop)]
[
IntentFilter
(
actions: new { Intent.ActionView },
Categories = new { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = “com.okta.dev-xxxxxxx”,
DataPath = “/callback”
)]
public class LoginCallbackInterceptorActivity : Activity
{

}

Any help will be appreciated

Kind Regards
Andy