Closed JonathanJPereira closed 1 year ago
Hi @JonathanJPereira!
Great to see that you are using the plugin. Could you try adding a scope like this scopes: ['api://<client id>/user.read']
, where <client id>
represents the application ID from your app registration? If this works, we will update the documentation accordingly.
Please let me know!
Thank you so much for that, it worked! @bartwesselink
But now when I press the button, only my console.log appears, I'm going to look for something I did wrong.
My return:
2022-10-25 12:12:49.038 13000-13000/com.carewebsolutions.celatools I/Capacitor/Console: File: http://localhost/src_app_pages_acesso_login_login_module_ts.js - Line 148 - Msg: call MSAuth
2022-10-25 12:12:49.080 13000-13171/com.carewebsolutions.celatools W/LibraryConfiguration: [2022-10-25 15:12:49 - thread_name : CapacitorPlugins, correlation_id : 2df1adb8-dfe8-4242-84f7-ea02920938f7] MsalConfiguration was already initialized Android 31
2022-10-25 12:12:49.100 13000-13171/com.carewebsolutions.celatools W/LocalMSALController:getDeviceMode: [2022-10-25 15:12:49 - thread_name : pool-6-thread-4, correlation_id : b031c4b1-5a56-405f-beb2-087588897393] LocalMSALController is not eligible to use the broker. Do not check sharedDevice mode and return false immediately. Android 31
2022-10-25 12:12:49.134 13000-13171/com.carewebsolutions.celatools W/Telemetry: [2022-10-25 15:12:49 - thread_name : main, correlation_id : UNSET] Telemetry is disabled because the Telemetry context or configuration is null Android 31
I'm researching what it's about
The first time it calls, just the console.log, even
Could you show me what your call looks like, from the browser/JavaScript side?
Could you show me what your call looks like, from the browser/JavaScript side?
It is like this
async onLogin(value) {
console.log('call MSAuth');
const result = await MsAuthPlugin.login({
clientId: '********-86ed-4a80-90a2-9cf2f39c08ea',
keyHash: ********rIeQyoc3+mckmcEUp4=',
tenant: '********-8f55-4f53-b2ab-3d5018045ba0',
scopes: ['api://********-86ed-4a80-90a2-9cf2f39c08eas/user.read']
});
console.log('end MSAuth');
this.accessApp(result);
}
accessApp(result) {
console.log('here is acessApp');
if (result && result.accessToken) {
const accessToken = result.accessToken;
if (accessToken) {
this.loginStorage.toggleSaveAccount(JSON.stringify(accessToken));
this.router.navigateByUrl('home/home');
}
}
}
@bartwesselink the import is like this
import { MsAuthPlugin } from '@recognizebv/capacitor-plugin-msauth';
@JonathanJPereira thanks for sending the call. What is the result, does something happen? Do you see the the auth screen, are you able to login? Do you receive a token?
@bartwesselink when I press the button it just runs the console.log "call MSAuth" and it looks like it's stuck on 'await', it doesn't open any screens and nothing runs afterwards. I can't get the token.
I have no way to test it, but another dev said it's working on IOS.
@bartwesselink in version 3.0.0 is giving this error. In other versions, no. It seems that some package is missing, but I don't know what to do.
Task :recognizebv-capacitor-plugin-msauth:compileDebugJavaWithJavac FAILED
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\DefaultPublicClientApplicationFactory.java:3: error: package android.content does not exist
import android.content.Context;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\PublicClientApplicationFactory.java:3: error: package android.content does not exist
import android.content.Context;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\DefaultPublicClientApplicationFactory.java:15: error: cannot find symbol
@NonNull Context context,
^
symbol: class Context
location: class DefaultPublicClientApplicationFactory
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\PublicClientApplicationFactory.java:12: error: cannot find symbol
@NonNull final Context context,
^
symbol: class Context
location: interface PublicClientApplicationFactory
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:3: error: package android does not exist
import android.Manifest;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:26: error: package org.json does not exist
import org.json.JSONArray;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:27: error: package org.json does not exist
import org.json.JSONException;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:28: error: package org.json does not exist
import org.json.JSONObject;
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:178: error: cannot find symbol
throws MsalException, InterruptedException, IOException, JSONException {
^
symbol: class JSONException
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:209: error: cannot find symbol
) throws MsalException, InterruptedException, IOException, JSONException {
^
symbol: class JSONException
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:251: error: cannot find symbol
private File writeJSONObjectConfig(JSONObject data) throws IOException {
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:32: error: package Manifest does not exist
permissions = { @Permission(alias = "network", strings = { Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.INTERNET }) }
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:32: error: package Manifest does not exist
permissions = { @Permission(alias = "network", strings = { Manifest.permission.ACCESS_NETWORK_STATE, Manifest.permission.INTERNET }) }
^
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:58: error: cannot access JSONArray
call.getArray("scopes").toList(),
^
class file for org.json.JSONArray not found
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:64: error: cannot find symbol
JSONArray scopes = new JSONArray(Arrays.asList(tokenResult.getScopes()));
^
symbol: class JSONArray
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:64: error: cannot find symbol
JSONArray scopes = new JSONArray(Arrays.asList(tokenResult.getScopes()));
^
symbol: class JSONArray
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:123: error: cannot access Activity
.startAuthorizationFromActivity(this.getActivity())
^
class file for android.app.Activity not found
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:213: error: cannot find symbol
String redirectUri = "msauth://" + getActivity().getApplicationContext().getPackageName() + "/" + urlEncodedKeyHash;
^
symbol: method getApplicationContext()
location: class AppCompatActivity
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:215: error: cannot find symbol
JSONObject authorityConfig = new JSONObject();
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:215: error: cannot find symbol
JSONObject authorityConfig = new JSONObject();
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:221: error: cannot find symbol
authorityConfig.put("audience", (new JSONObject()).put("type", "AzureADMultipleOrgs").put("tenant_id", tenantId));
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:230: error: cannot find symbol
JSONObject configFile = new JSONObject();
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:230: error: cannot find symbol
JSONObject configFile = new JSONObject();
^
symbol: class JSONObject
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:236: error: cannot find symbol
configFile.put("authorities", (new JSONArray()).put(authorityConfig));
^
symbol: class JSONArray
location: class MsAuthPlugin
C:\websolution.cella_tools-main\node_modules\@recognizebv\capacitor-plugin-msauth\android\src\main\java\nl\recognize\msauthplugin\MsAuthPlugin.java:252: error: cannot find symbol
File config = new File(getActivity().getFilesDir() + "auth_config.json");
^
symbol: method getFilesDir()
location: class AppCompatActivity
25 errors
Thank you for supplying the additional logs. You can only use version 3.x with Capacitor 4, otherwise you might run into these issues. Please make sure that that is the case.
Do you see any logging in your LogCat window when you press the button? Apart from what you already sent, because those do not seem to be blocking issues.
Thanks for your help @bartwesselink, I updated the capacitor and version 3.0.0 worked.
But it still gives the same problem as before, I press the button and no error appears in the console.log.
I made a short video demonstrating: https://www.youtube.com/watch?v=nJSQ53vcQEs&ab_channel=JonathanPereira
Thanks for the video, it helps. So, there is no output at all. What you could try, is registering the plugin manually like this, in your MainActivity (please also add the imports):
@Override
public void onCreate(Bundle savedInstanceState) {
registerPlugin(MsAuthPlugin.class);
super.onCreate(savedInstanceState);
}
If this does not work, you will have to give us a minimal setup repository that we can use to reproduce the problem.
@JonathanJPereira, have you fixed the problem? I have same issue like yours to use this plugin on Android.
@wangzhengjiang does the solution above work for you?
@bartwesselink , thanks for creating this Plugin. I added above code into mainactivity, but still not working.
@JonathanJPereira, have you fixed the problem? I have same issue like yours to use this plugin on Android.
Sorry for the delay, unfortunately I couldn't solve the problem
@wangzhengjiang @JonathanJPereira sorry for the delayed response. I have tried to replicate this, but had no luck. Is anybody of you able to create an empty repository that has the problem you are describing? This will help debugging.
@bartwesselink, I tried again and redo the app setting in azure portal, basically generated the hash again, it is working now.
@wangzhengjiang great to hear that. @JonathanJPereira does the same hold for you?
@wangzhengjiangótimo ouvir isso.@JonathanJPereirao mesmo vale para você?
Unfortunately I no longer have access to the previous code
Hello, thanks for developing this plugin!
I'm trying to make the plugin work on android but I'm getting an error and I can't proceed