Linking: addEventListener 'url' callback function not called during Oauth2 flow
Environment
- react-native -v:
react-native-cli: 2.0.1
react-native: 0.52.2
- npm ls rnpm-plugin-windows:
[email protected]
- npm ls react-native-windows:
[email protected]
- node -v:
v9.4.0
- npm -v:
5.6.0
- yarn --version:
N/A
Target Platform: UWP Target Platform Version(s): 10.0.14393 Target Device(s): Desktop Development Operating System: Windows Visual Studio Version: 2017
Steps to Reproduce
Run following code:
import React, { Component } from 'react';
import {
AppRegistry,
StyleSheet,
Text,
View,
TouchableOpacity,
Linking
} from 'react-native';
export default class OauthExample extends Component {
_handleURL(event) {
console.log(event.url);
}
_microsoftLogin() {
Linking.openURL([
'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
'?response_type=code',
'&client_id='+'---your client id---',
'&redirect_uri=---your redirect url---',
'&scope=User.read' // Specify permissions
].join(''));
}
componentDidMount() {
console.log('componentDidMount');
Linking.addEventListener('url', this._handleURL);
}
render() {
return (
<View style={styles.container}>
<TouchableOpacity onPress={this._microsoftLogin}>
<Text style={styles.welcome}>
Microsoft Login!
</Text>
</TouchableOpacity>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
}
});
AppRegistry.registerComponent('auth', () => OauthExample);
Expected Behavior
- Click the 'Microsoft Login!' text
- Browser launches MS log in
- Log into MS account
- Expect _handleURL() function to be called on App
Actual Behavior
_handleURL() function is not called.
@nomartin - can you debug the native app and confirm in OnActivated is called in App.xaml.cs? If so, what is the value of the Kind property on the IActivatedEventArgs argument?
Just confirmed it's a Protocol activation. Should be working...
@rozele - Tried with the versions above (same project) and see the same issue. No console log and the debugger will not break for me in OnActivate.
I created a new project using RN v0.55 and RNW v0.54 (RNW v0.55 isn't available). That project consistently has the following error:

Both TouchableOpacity and Button cause this error. NOTE: Simple <View><Text>text</Text></View> works.
Will try again tomorrow.
ok - downgraded to RN 0.54. Error goes away.
Still cannot get the breakpoint to fire. However, if this is working for you then I'd suspect user-error. You can just close this iisue and I'll watch it on my end.
Have you found a solution @nomartin ? I can't make the listener trigger the function... I've seen around that many people are dealing with this issue as well...
@nomartin probably a dumb question, but I assume you've updated the Package.appxmanifest to include the app protocol, correct?
Yes, actually, Linking.getInitialURL() works. It is just that, when the app is open but running in the back, when I go from listener seems to have no effect...
@fedealconada Hmm - good point - when I tried to repro, I believe I was debugging with Visual Studio, which means the app likely didn't suspend.
Can you try to run the app with debugger attached (so the app is still "foreground") and see if the flow works correctly? I'd like to make sure the issue is isolated to suspended apps.
@rozele I've just figured out that this is the Microsoft react-native-windows repo... I have this problem with react-native, not using windows :/ Anyways, it's the same problem and I've seen that many people has it...
@nomartin please let me know if this has been resolved in RNW 0.55