1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-04-20 11:28:40 +02:00

76 lines
1.8 KiB
JavaScript
Raw Normal View History

2017-07-06 19:29:09 +00:00
import React, { Component } from 'react';
import { View } from 'react-native';
import { WebView, Button } from 'react-native';
import { connect } from 'react-redux'
import { Log } from 'lib/log.js'
2017-07-06 19:48:17 +00:00
import { Setting } from 'lib/models/setting.js'
2017-07-06 19:29:09 +00:00
import { ScreenHeader } from 'lib/components/screen-header.js';
2017-07-06 19:48:17 +00:00
import { reg } from 'lib/registry.js';
2017-07-06 19:29:09 +00:00
import { _ } from 'lib/locale.js';
class OneDriveLoginScreenComponent extends React.Component {
static navigationOptions(options) {
return { header: null };
}
constructor() {
super();
this.state = { webviewUrl: '' };
this.authCode_ = null;
}
componentWillMount() {
this.setState({
2017-07-06 19:48:17 +00:00
webviewUrl: reg.oneDriveApi().authCodeUrl(this.redirectUrl()),
2017-07-06 19:29:09 +00:00
});
}
redirectUrl() {
return 'https://login.microsoftonline.com/common/oauth2/nativeclient';
}
async webview_load(noIdeaWhatThisIs) {
// This is deprecated according to the doc but since the non-deprecated property (source)
// doesn't exist, use this for now. The whole component is completely undocumented
// at the moment so it's likely to change.
const url = noIdeaWhatThisIs.url;
2017-07-06 19:48:17 +00:00
if (!this.authCode_ && url.indexOf(this.redirectUrl() + '?code=') === 0) {
console.info('URL: ' + url);
2017-07-06 19:29:09 +00:00
2017-07-06 19:48:17 +00:00
let code = url.split('?code=');
this.authCode_ = code[1];
2017-07-06 19:29:09 +00:00
2017-07-06 19:48:17 +00:00
await reg.oneDriveApi().execTokenRequest(this.authCode_, this.redirectUrl(), true);
2017-07-06 19:29:09 +00:00
2017-07-06 19:48:17 +00:00
this.authCode_ = null;
2017-07-06 19:29:09 +00:00
}
}
render() {
const source = {
uri: this.state.webviewUrl,
}
return (
<View style={{flex: 1}}>
<ScreenHeader navState={this.props.navigation.state} />
<WebView
source={source}
style={{marginTop: 20}}
onNavigationStateChange={(o) => { this.webview_load(o); }}
/>
</View>
);
}
}
const OneDriveLoginScreen = connect(
(state) => {
return {};
}
)(OneDriveLoginScreenComponent)
export { OneDriveLoginScreen };