javaandroidtypescriptauthenticationmfp

Login fail in mfp WL.Client.createSecurityCheckChallengeHandler() or WLAuthorizationManager.login()


The following is code in mfp.auth.service.ts file:

performLogin(username: string, loginRequest: RequestModel<LoginRequestModel>): Observable<any> {
        let mfpAuthResponse: any;
        let userLoginChallengeHandler = WL.Client.createSecurityCheckChallengeHandler(this.securityCheckName);
        (userLoginChallengeHandler as any).securityCheckName = this.securityCheckName;
        console.log("this.securityCheckName is " + this.securityCheckName);
        userLoginChallengeHandler.handleSuccess = (loginSuccess) => {
            console.log("handleSuccess mfpAuthResponse is " + mfpAuthResponse);
            if (!mfpAuthResponse) {
                console.log("handle here");
                mfpAuthResponse = {
                    id: loginSuccess.id,
                    accessToken: loginSuccess.user.attributes.access_token,
                    tokenType: loginSuccess.user.attributes.token_type,
                    expiresIn: loginSuccess.user.attributes.expires_in,
                    scope: loginSuccess.user.attributes.scope,
                    clientId: loginSuccess.user.attributes.client_id
                };
            }
        };
        console.log("line 41");
        userLoginChallengeHandler.handleFailure = (loginError) => {
            console.log("handleFailure " + loginError);
            if (!mfpAuthResponse) {
                mfpAuthResponse = loginError;
            }
        };

        let authRequest = {
            requestHeader: {
                deviceId: this.sessionService.getDeviceId(),
                channelTime: new Date().toISOString()
            },
            requestBody: loginRequest.requestBody
        }
        this.currentLoginGrantType = loginRequest.requestBody.grant_type;
        console.log("ready to return ");
        return from(new Promise(
            (resolve, reject) => {
                console.log("line 60");
                WLAuthorizationManager.login(this.securityCheckName,
                    {
                        'authorization': environment.authorization,
                        'authRequest': JSON.stringify(authRequest),
                        'authCode': this.service.getHashMAC(authRequest, this.sessionService.getHashKey()),
                        'authUser': username
                    }
                ).then(
                    (res) => resolve(mfpAuthResponse),
                    (err) => reject(mfpAuthResponse)
                );
            }
        ));
        console.log("line 79 end");
    }

At first, I am using mfp developer kit, its working fine and I am able to login to my app and see the landing page. By putting some log, I can found that it will go to WLAuthorizationManager.login() , and then go to the handleSuccess part to indicate the login is success. Other than this, I can also see the request come into my backend service, it will run the validateCredentials() method in my UserAuthentication.java. I am not understand how this work, but I will study on it after this.

Then I stop my mfp developer kit server, and I Install Installation Manager, install WebSphere Application Server Liberty Core, and then install the MobileFirst Server that I download from proper IBM website. I am doing this base on this website: https://www.ibm.com/support/knowledgecenter/SSHS8R_8.0.0/com.ibm.worklight.installconfig.doc/install_config/t_install_mfp_server_cmdline_mode.html?view=embed#t_install_mfp_server__1

I found that I am not able to login to my app when I am using the proper MFP server. Base on the console log, I can see it go to the console.log("line 60 " + this.securityCheckName);, and then no longer go to handleSuccess. Also, it didnt come to the backend code, which is the validateCredentials I mention just now. There is no error in my mfp server log, and no error in my backend service api log. In my chrome that I use to inspect element of my android phone, there is no error as well. I suspect something wrong in the WLAuthorizationManager.login(), but there is no error log, I have no idea how to trace and fix it.

I suspect there are something I need to configure in the proper mfp server? Because the code is working fine If I using the mfp developer kit server. (The mfp developer kit server is just 1 command to install, I think it already help me configure properly.)

I am new to mfp and typescript, and still no idea how to fix this after googling around for few days. Kindly advise on this.


Solution

  • For those who having problem like me, I finally find out what is the problem. The Mfp 8.0 base is since 2016, After I install fix-pack provided by IBM on January 2020, then the problem solved. I just suspect that after 2016, android and IOS code already updated, thus it will have this bug if not install fixpack.