GSingh01/ad-b2c-react-native

Problem with google singin on iOS

Closed this issue · 13 comments

Hello

I am using the library for a project where the user can login with email and with a google account. The version for android is working perfectly. Now I am working on iOS version and the google login doesn't work. It stuck on a white screen after the google login process and never call onSuccess method. No errors returned from the web view. Any ideas where is the problem?

<LoginView
                appId="*******"
                redirectURI="com.onmicrosoft.mytenant.exampleapp://oauth/redirect"
                tenant="ivanb2c"
                loginPolicy="B2C_1_signupsignin1"
                passwordResetPolicy="B2C_1_passwordreset1"
                profileEditPolicy="B2C_1_pofileediting1"
                onSuccess={this.onLogin}
                onFail={this.onFail}
                secureStore={secureStore}
                renderLoading={() => { return (<View><Text>Loading</Text></View>) }}
            />

Info.plist

<key>CFBundleURLTypes</key>
	<array>
		<dict>
			<key>CFBundleTypeRole</key>
			<string>Editor</string>
			<key>CFBundleURLSchemes</key>
			<array>
				<string>com.onmicrosoft.mytenant.exampleapp</string>
			</array>
		</dict>
	</array>

I had this same problem. Google login seems to redirect twice, the first causes the onShouldStartLoadWithRequest method in LoginView to return false and stop loading, so it never actually processes the access token request.

I was able to work around it by doing the following:

  1. Update LoginView.js to allow overriding that method
    `return (
    <WebView ...

onShouldStartLoadWithRequest={this.props.onShouldStartLoadWithRequest ?? this.onShouldStartLoadWithRequest}
...`

  1. override the method to always return true
    `<LoginView
    userAgent={
    'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15'
    }...

onShouldStartLoadWithRequest={() => {
return true;
}}
`
Note that I've also had to provide an updated UA string because google rejects the default.

credit to @stevef51 for the idea of bypassing onShouldStartLoadWithRequest
#13 (comment)

This might be a better option, and works for me with both google and twitter login:

LoginView.js

onShouldStartLoadWithRequest(navState) {
    const result = adService.getLoginFlowResult(navState.url);
    if (
      result.requestType === RequestType.Ignore ||
      result.requestType === RequestType.Code && !navState.loading ||
      result.requestType === RequestType.PasswordReset ||
      result.requestType === RequestType.Cancelled
    ) {
      this.webView.stopLoading();
      return false;
    }

    return true;
  }

No one of the above suggestions worked :(

did you also update the user agent string? That was the first problem I encountered

@michaelburch and @IvanKalachev Thanks for bringing this up. I will try to test again with IOS and incorporate your suggestions in to the library.
Again you are also most welcome to submit a PR with the above change :)

thanks @GSingh01 ! I submitted PR #23 after some additional testing. I have a fairly complete sample app working now that I will share soon. Thanks for this great library!

@michaelburch thanks alot for PR.

@michaelburch Your changes are released, please install 1.1.5 and verify if it works as expected on ios and android. Feel free to close once tested

Thanks for contributing 💯

@IvanKalachev can you please verify with latest 1.1.5 release

Not working with the latest version (1.1.5) - again white screen after google login process. Can somebody share a simple working project? I suppose that the problem is in my project (iOS) settings.

@IvanKalachev I'll share my working project ASAP. In the mean time, I suspect there's a problem with your redirectURI. I had problems with google login on iOS with any redirectURI that didn't start with https

I've confirmed that Google login works with the latest release on both Android and iOS.

@IvanKalachev I created a sample app that you can use for reference:
https://github.com/michaelburch/react-native-aad-b2c-sample

Everything is working fine. Thanks!