5
5
import android .support .v7 .app .AppCompatActivity ;
6
6
import android .util .Log ;
7
7
8
- import com .facebook .FacebookSdk ;
9
- import com .facebook .appevents .AppEventsLogger ;
10
8
import com .firebase .client .AuthData ;
11
9
import com .firebase .client .Firebase ;
12
10
import com .firebase .client .FirebaseError ;
25
23
import java .util .HashMap ;
26
24
import java .util .Map ;
27
25
28
- import twitter4j .Twitter ;
29
-
30
26
public abstract class FirebaseLoginBaseActivity extends AppCompatActivity {
31
27
32
28
private final String LOG_TAG = "FirebaseLoginBaseAct" ;
@@ -96,7 +92,7 @@ protected void onCreate(Bundle savedInstanceState) {
96
92
mFacebookAuthHelper = new FacebookAuthHelper (this , new TokenAuthHandler () {
97
93
@ Override
98
94
public void onTokenReceived (FirebaseOAuthToken token ) {
99
- authenticateRefWithProvider ( token . provider , token . token );
95
+ authenticateRefWithFirebaseOAuthToken ( token );
100
96
}
101
97
102
98
@ Override
@@ -113,7 +109,7 @@ public void onError(Exception ex) {
113
109
mGoogleAuthHelper = new GoogleAuthHelper (this , new TokenAuthHandler () {
114
110
@ Override
115
111
public void onTokenReceived (FirebaseOAuthToken token ) {
116
- authenticateRefWithProvider ( token . provider , token . token );
112
+ authenticateRefWithFirebaseOAuthToken ( token );
117
113
}
118
114
119
115
@ Override
@@ -130,7 +126,7 @@ public void onError(Exception ex) {
130
126
mTwitterAuthHelper = new TwitterAuthHelper (this , new TokenAuthHandler () {
131
127
@ Override
132
128
public void onTokenReceived (FirebaseOAuthToken token ) {
133
- authenticateRefWithProvider ( token . provider , token );
129
+ authenticateRefWithFirebaseOAuthToken ( token );
134
130
}
135
131
136
132
@ Override
@@ -146,7 +142,8 @@ public void onError(Exception ex) {
146
142
}
147
143
148
144
public void onActivityResult (int requestCode , int resultCode , Intent data ) {
149
- Log .d ("BASE" , "ACTIVITY" );
145
+ Log .d ("BASE" , "ACTIVITY" + data .toString ());
146
+ mFacebookAuthHelper .mCallbackManager .onActivityResult (requestCode , resultCode , data );
150
147
mTwitterAuthHelper .onActivityResult (requestCode , resultCode , data );
151
148
}
152
149
@@ -168,57 +165,53 @@ public void onAuthStateChanged(AuthData authData) {
168
165
});
169
166
}
170
167
171
- private void authenticateRefWithProvider (String provider , String token ) {
172
- getFirebaseRef ().authWithOAuthToken (provider , token , new Firebase .AuthResultHandler () {
173
- @ Override
174
- public void onAuthenticated (AuthData authData ) {
175
- // Do nothing. Auth updates are handled in the AuthStateListener
176
- }
177
-
178
- @ Override
179
- public void onAuthenticationError (FirebaseError firebaseError ) {
180
- onFirebaseLoginError (firebaseError );
181
- }
182
- });
183
- }
184
-
185
- private void authenticateRefWithProvider (String provider , FirebaseOAuthToken token ) {
186
- Map <String , String > options = new HashMap <>();
187
- options .put ("oauth_token" , token .token );
188
- options .put ("oauth_token_secret" , token .secret );
189
- options .put ("user_id" , token .uid );
168
+ private void authenticateRefWithFirebaseOAuthToken (FirebaseOAuthToken token ) {
169
+ if (token .mode == FirebaseOAuthToken .SIMPLE ) {
170
+ // Simple mode is used for Facebook and Google auth
171
+ getFirebaseRef ().authWithOAuthToken (token .provider , token .token , new Firebase .AuthResultHandler () {
172
+ @ Override
173
+ public void onAuthenticated (AuthData authData ) {
174
+ // Do nothing. Auth updates are handled in the AuthStateListener
175
+ }
190
176
191
- getFirebaseRef ().authWithOAuthToken (provider , options , new Firebase .AuthResultHandler () {
192
- @ Override
193
- public void onAuthenticated (AuthData authData ) {
194
- // Do nothing. Auth updates are handled in the AuthStateListener
195
- }
177
+ @ Override
178
+ public void onAuthenticationError (FirebaseError firebaseError ) {
179
+ onFirebaseLoginError (firebaseError );
180
+ }
181
+ });
182
+ } else if (token .mode == FirebaseOAuthToken .COMPLEX ) {
183
+ // Complex mode is used for Twitter auth
184
+ Map <String , String > options = new HashMap <>();
185
+ options .put ("oauth_token" , token .token );
186
+ options .put ("oauth_token_secret" , token .secret );
187
+ options .put ("user_id" , token .uid );
188
+
189
+ getFirebaseRef ().authWithOAuthToken (token .provider , options , new Firebase .AuthResultHandler () {
190
+ @ Override
191
+ public void onAuthenticated (AuthData authData ) {
192
+ // Do nothing. Auth updates are handled in the AuthStateListener
193
+ }
196
194
197
- @ Override
198
- public void onAuthenticationError (FirebaseError firebaseError ) {
199
- onFirebaseLoginError (firebaseError );
200
- }
201
- });
195
+ @ Override
196
+ public void onAuthenticationError (FirebaseError firebaseError ) {
197
+ onFirebaseLoginError (firebaseError );
198
+ }
199
+ });
200
+ }
202
201
}
203
202
204
203
private String getFirebaseUrlFromConfig () {
205
204
String firebaseUrl ;
206
205
try {
207
-
208
206
InputStream inputStream = getAssets ().open ("firebase-config.json" );
209
-
210
207
int size = inputStream .available ();
211
-
212
208
byte [] buffer = new byte [size ];
213
209
214
210
inputStream .read (buffer );
215
-
216
211
inputStream .close ();
217
212
218
213
String json = new String (buffer , "UTF-8" );
219
-
220
214
JSONObject obj = new JSONObject (json );
221
-
222
215
firebaseUrl = obj .getString ("firebaseUrl" );
223
216
224
217
} catch (IOException ex ) {
0 commit comments