Add Authentication to Your Xamarin App with OpenID Connect

Vishal Pachori

you can try this:-
var client = new RestClient("{orgURL}/oauth2/v1/token");
var request = new RestRequest(Method.POST);

request.AddHeader(“Content-Type”, “application/x-www-form-urlencoded”);
request.AddParameter( “grant_type=refresh_token&refresh_token=<your_refresh_token>&redirect_uri=<your_callback_url>&client_id=<your_client id=”">", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);

Ankit Parekh

Tried this:
var client = new RestClient($"{Configuration.OrgUrl}/oauth2/v1/token");
var request = new RestRequest(Method.POST);

request.AddHeader(“Content-Type”, “application/x-www-form-urlencoded”);
request.AddParameter($“grant_type=refresh_token&refresh_token={result.RefreshToken}&redirect_uri={Configuration.LoginRedirectUri}&client_id={Configuration.ClientId}”, ParameterType.RequestBody);

IRestResponse response = client.Execute(request);

getting below response:
{“error”:“invalid_client”,“error_description”:“No client credentials found.”}

Let me know if you may guess, what actually is missing or wrong in above request.

Vishal Pachori

Have you crosschecked the validity of Client ID with this error the client ID seems to be invalid

Ankit Parekh

By Client ID you mean the one provided by okta when we create an application, right?

Because I am able to make login with the same client id and get authorization response as explained here.

Andrew Nixon

Hi,
I’m new to Xamarin so apologies if this is question has an obvious answer.

When compiling this project it generates the merged AndroidManifest.xml file with an Activity and IntentFilter for the redirect back to the app after logging in which looks like this:

<activity android:name=“net.openid.appauth.AuthorizationManagementActivity” android:exported=“false” android:launchmode=“singleTask” android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
<activity android:name=“net.openid.appauth.RedirectUriReceiverActivity” android:exported=“true”>
<intent-filter>
<action android:name=“android.intent.action.VIEW”/>
<category android:name=“android.intent.category.DEFAULT”/>
<category android:name=“android.intent.category.BROWSABLE”/>
<data android:scheme="${appAuthRedirectScheme}"/>
</intent-filter>
</activity>

My question is: where does it get the value for {appAuthRedirectScheme} and/or where can I set it?

My app is opening the login dialog but then failing on the redirect.

Thanks in advance…

Nate Barbettini

See this section of the tutorial: https://developer.okta.com/…

If you are using Okta, the scheme is usually your Okta domain.

Balakrishnan Srinivasan

Did you found the solution,
Please share if anything available.

Mr003

Hi I’m new to xamarin and okta. I did the steps as per the article but I’m getting an error at the line

_authService = new AuthorizationService(MainActivity.Instance);

at MainActivity.Instance with an error message on the emulator -

“System.Reflection.TargetInvocationException: ‘Exception has been thrown by the target of an invocation.’”

“App has stopped…open app again”

saurav kumar

@vishalpachori, @Ankit Parekh, Did you resolve this issue? I am trying to get accesstoken in Xamarin APP using refresh token but not able to get, tried the way above mentioned but it is not happening. If you can provide any code snippet it will be helpful.