Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to login when external browser authentication setting is turned on #2642

Open
hemantsumanmetacube opened this issue Dec 2, 2024 · 15 comments

Comments

@hemantsumanmetacube
Copy link

Please fill out the following details:

  1. Version of Mobile SDK Used: v12.0.1
  2. Issue found in Native App or Hybrid App: Hybrid
  3. OS Version: Android 13 and 14
  4. Error Log:

2024-12-02 17:32:35.712 32316-32483 OAuthWebViewHelper com.tier1crm.tier1mobilenow D token response -> null 2024-12-02 17:32:35.896 32316-32483 .tier1mobilenow com.tier1crm.tier1mobilenow W Verification of java.lang.Object com.salesforce.androidsdk.ui.OAuthWebviewHelper$onAuthFlowComplete$1.invokeSuspend(java.lang.Object) took 172.044ms (499.87 bytecodes/s) (3744B approximate peak alloc) 2024-12-02 17:32:39.561 32316-32483 OAuthWebViewHelper com.tier1crm.tier1mobilenow W Exception thrown while retrieving token response java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.Request$Builder.url, parameter url at okhttp3.Request$Builder.url(Unknown Source:2) at com.salesforce.androidsdk.auth.OAuth2.callIdentityService(OAuth2.java:426) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$FinishAuthTask.performRequest(OAuthWebviewHelper.kt:1204) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$FinishAuthTask.performRequest(OAuthWebviewHelper.kt:1199) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask.doInBackground(OAuthWebviewHelper.kt:966) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invokeSuspend(OAuthWebviewHelper.kt:949) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invoke(Unknown Source:8) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask.execute$SalesforceSDK_debug(OAuthWebviewHelper.kt:948) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onAuthFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:836) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) 2024-12-02 17:32:39.574 32316-32483 OAuthWebViewHelper com.tier1crm.tier1mobilenow E Error: Authentication error. Please try again. java.lang.NullPointerException: Parameter specified as non-null is null: method okhttp3.Request$Builder.url, parameter url at okhttp3.Request$Builder.url(Unknown Source:2) at com.salesforce.androidsdk.auth.OAuth2.callIdentityService(OAuth2.java:426) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$FinishAuthTask.performRequest(OAuthWebviewHelper.kt:1204) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$FinishAuthTask.performRequest(OAuthWebviewHelper.kt:1199) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask.doInBackground(OAuthWebviewHelper.kt:966) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invokeSuspend(OAuthWebviewHelper.kt:949) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invoke(Unknown Source:8) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask$execute$2.invoke(Unknown Source:4) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$BaseFinishAuthFlowTask.execute$SalesforceSDK_debug(OAuthWebviewHelper.kt:948) at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onAuthFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:836) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115) at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100) at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697) at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684) 2024-12-02 17:32:39.581 32316-32316 Compatibil...geReporter com.tier1crm.tier1mobilenow D Compat change id reported: 147798919; UID 10468; state: ENABLED

@hemantsumanmetacube
Copy link
Author

In OauthWebViewHelper.kt file, after user is logged in, onAuthFlowComplete is called, the first parameter tr is null.

open fun onAuthFlowComplete(tr: TokenEndpointResponse?, nativeLogin: Boolean = false) {
d(TAG, "token response -> $tr")
CoroutineScope(IO).launch {
try{
FinishAuthTask().execute(tr, nativeLogin)
}catch (e:Exception){
e.message?.let { Log.d("tag", it) }
}
}
}

@brandonpage
Copy link
Contributor

brandonpage commented Dec 2, 2024

OAuthWebViewHelper com.tier1crm.tier1mobilenow D token response -> null

It looks like you are trying to login to a server that is not a Salesforce instance.

Edit: Sorry, I read this log line wrong (since it has changed since 12.0.1). I thought the package name was the url of the token response.

@hemantsumanmetacube
Copy link
Author

I don't think this is the case, I am trying to login to a org and using this url -> https://*.sandbox.my.salesforce.com

@brandonpage
Copy link
Contributor

@hemantsumanmetacube Is this a consistent issue? Is the sandbox org you are logging into added to the servers list or thought the "Use Custom Domain" button in the webview?

@hemantsumanmetacube
Copy link
Author

Yes, this is a consistent issue. It is added in the servers list and trying to login after that.

@brandonpage
Copy link
Contributor

Are you using browser based authentication? If so which browser? If you got to the native identity call I assume that means the necessary intent filter is correct.

Are you using the default Web Server flow or User Agent flow for authentication?

What OAuth scopes are selected on the connected app?

What are the OAuth Policies and Session Policies of the connected app?

@hemantsumanmetacube
Copy link
Author

Yes, We are using browser based authentication. The issue is reproducible on Android Devices (Chrome), and we are using default web server flow.

Screenshot 2024-12-05 at 10 42 04 AM Screenshot 2024-12-05 at 10 42 11 AM

@brandonpage
Copy link
Contributor

@hemantsumanmetacube Is require secret for web server flow unchecked in your connected app?

Screenshot 2024-12-04 at 9 46 38 PM

@hemantsumanmetacube
Copy link
Author

Yes, it is unchecked

@hemantsumanmetacube
Copy link
Author

hemantsumanmetacube commented Dec 9, 2024

After further debugging, i found that makeTokenEndpointRequest function in OAuth2.java file is called to and it makes a POST REST Call to https://qamain--sb1.sandbox.my.salesforce.com/services/oauth2/token?device_id=DEVICE_ID, In response we get 400 and thus the token is set to null.

private static TokenEndpointResponse makeTokenEndpointRequest(HttpAccess httpAccessor,
URI loginServer,
FormBody.Builder formBodyBuilder)
throws OAuthFailedException, IOException {
final StringBuilder sb = new StringBuilder(loginServer.toString());
sb.append(OAUTH_TOKEN_PATH);
sb.append(QUESTION).append(DEVICE_ID).append(EQUAL).append(SalesforceSDKManager.getInstance().getDeviceId());
final String refreshPath = sb.toString();
final RequestBody body = formBodyBuilder.build();
final Request request = new Request.Builder().url(refreshPath).post(body).build();
final Response response = httpAccessor.getOkHttpClient().newCall(request).execute();
if (response.isSuccessful()) {
return new TokenEndpointResponse(response);
} else {
throw new OAuthFailedException(new TokenErrorResponse(response), response.code());
}
}

@hemantsumanmetacube
Copy link
Author

External Browser authentication is also not working on freshly created app using forcehybrid. Getting below error:

Exception occurred while making token request
com.salesforce.androidsdk.auth.OAuth2$OAuthFailedException: invalid_grant:invalid code verifier
at com.salesforce.androidsdk.auth.OAuth2.makeTokenEndpointRequest(OAuth2.java:451)
at com.salesforce.androidsdk.auth.OAuth2.exchangeCode(OAuth2.java:331)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invokeSuspend(OAuthWebviewHelper.kt:735)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:8)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.doCodeExchangeEndpoint(OAuthWebviewHelper.kt:732)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.access$doCodeExchangeEndpoint(OAuthWebviewHelper.kt:152)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onWebServerFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:727)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2024-12-16 12:59:39.269 24964-25197 OAuthWebViewHelper com.tier1crm.tier1mobilenow E Token Request Error: invalid_grant:invalid code verifier
com.salesforce.androidsdk.auth.OAuth2$OAuthFailedException: invalid_grant:invalid code verifier
at com.salesforce.androidsdk.auth.OAuth2.makeTokenEndpointRequest(OAuth2.java:451)
at com.salesforce.androidsdk.auth.OAuth2.exchangeCode(OAuth2.java:331)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invokeSuspend(OAuthWebviewHelper.kt:735)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:8)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.doCodeExchangeEndpoint(OAuthWebviewHelper.kt:732)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.access$doCodeExchangeEndpoint(OAuthWebviewHelper.kt:152)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onWebServerFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:727)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:100)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)

@brandonpage
Copy link
Contributor

Sorry, the team was busy with planning last week. Is this on 12.0.1? I would recommend you update to 12.2.0 because this sounds like an issue we have already fixed earlier this year.

@hemantsumanmetacube
Copy link
Author

i am getting the same error with SalesforceMobileSDK 12.2.0

2024-12-23 15:01:42.446 12859-13049 OAuthWebViewHelper com.tier1crm.tier1mobilenow E Exception occurred while making token request
com.salesforce.androidsdk.auth.OAuth2$OAuthFailedException: invalid_grant:invalid code verifier
at com.salesforce.androidsdk.auth.OAuth2.makeTokenEndpointRequest(OAuth2.java:495)
at com.salesforce.androidsdk.auth.OAuth2.exchangeCode(OAuth2.java:363)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invokeSuspend(OAuthWebviewHelper.kt:774)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:8)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.doCodeExchangeEndpoint(OAuthWebviewHelper.kt:771)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.access$doCodeExchangeEndpoint(OAuthWebviewHelper.kt:151)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onWebServerFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:766)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)
2024-12-23 15:01:42.455 12859-13049 OAuthWebViewHelper com.tier1crm.tier1mobilenow E Token Request Error: invalid_grant:invalid code verifier
com.salesforce.androidsdk.auth.OAuth2$OAuthFailedException: invalid_grant:invalid code verifier
at com.salesforce.androidsdk.auth.OAuth2.makeTokenEndpointRequest(OAuth2.java:495)
at com.salesforce.androidsdk.auth.OAuth2.exchangeCode(OAuth2.java:363)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invokeSuspend(OAuthWebviewHelper.kt:774)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:8)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$doCodeExchangeEndpoint$2.invoke(Unknown Source:4)
at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:78)
at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:167)
at kotlinx.coroutines.BuildersKt.withContext(Unknown Source:1)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.doCodeExchangeEndpoint(OAuthWebviewHelper.kt:771)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper.access$doCodeExchangeEndpoint(OAuthWebviewHelper.kt:151)
at com.salesforce.androidsdk.ui.OAuthWebviewHelper$onWebServerFlowComplete$1.invokeSuspend(OAuthWebviewHelper.kt:766)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:108)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:115)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:103)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:584)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:793)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:697)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:684)

@hemantsumanmetacube
Copy link
Author

@brandonpage Any update regarding this issue.

@hemantsumanmetacube
Copy link
Author

@brandonpage Any update regarding this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants