77 */
88
99import React , { Component } from 'react' ;
10- import { Platform , StyleSheet , Text , View } from 'react-native' ;
10+ import { Platform , StyleSheet , Text , View , Linking } from 'react-native' ;
11+ import OAuthManager from 'react-native-oauth' ;
1112
1213const instructions = Platform . select ( {
1314 ios : 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu' ,
@@ -16,8 +17,60 @@ const instructions = Platform.select({
1617 'Shake or press menu button for dev menu' ,
1718} ) ;
1819
20+ const OAUTH_CONFIG = {
21+ github : {
22+ client_id : Platform . select ( {
23+ ios : 'c8540af149a6bfe38a42' ,
24+ android : '075e7aaa056d3cb2c1ff'
25+ } ) ,
26+ client_secret : Platform . select ( {
27+ ios : 'e4d6e5d8787d1acf145ecd8f53a92b4de25cf0c5' ,
28+ android : '3ca8451b4da98a11f14fc4711f9b2dff327ba009'
29+ } ) ,
30+ } ,
31+ }
32+
33+ const OAUTH_APP_NAME = Platform . select ( {
34+ ios : 'mobilegithubpushnotificationsios' ,
35+ android : 'mobilegithubpushnotificationsandroid' ,
36+ } )
37+
1938type Props = { } ;
2039export default class App extends Component < Props > {
40+
41+ constructor ( ) {
42+ super ( )
43+ this . manager = new OAuthManager ( OAUTH_APP_NAME )
44+ console . log ( this . manager ) ;
45+ }
46+
47+ componentDidMount ( ) {
48+ this . manager . configure ( OAUTH_CONFIG ) ;
49+ console . log ( this . manager ) ;
50+ Linking . addEventListener ( 'url' , this . handleOpenURL ) ;
51+ this . work ( )
52+ }
53+
54+ componentWillUnmount ( ) {
55+ Linking . removeEventListener ( 'url' , this . handleOpenURL ) ;
56+ }
57+
58+ handleOpenURL = ( event ) => {
59+ console . log ( event . url ) ;
60+ }
61+
62+ work = async ( ) => {
63+ const { accounts } = await this . manager . savedAccounts ( )
64+ console . log ( 'account list: ' , accounts ) ;
65+ // try {
66+ // await this.manager.deauthorize('github')
67+ // const { accounts: accounts2 } = await this.manager.savedAccounts()
68+ // console.log('account list: ', accounts2);
69+ // } catch (err) {}
70+ const res = await this . manager . authorize ( 'github' , { scopes : 'notifications,read:user' } )
71+ console . log ( 'res' , res ) ;
72+ }
73+
2174 render ( ) {
2275 return (
2376 < View style = { styles . container } >
0 commit comments