Skip to content

Commit f222318

Browse files
committed
Copying over initial code
Change-Id: I7ab0b0ce6376e51ee37d4bfeadb6f607a11f4d80
1 parent 9e0a4eb commit f222318

File tree

128 files changed

+3380
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+3380
-0
lines changed

.gitignore

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
.gradle
2+
local.properties
3+
.idea
4+
build/
5+
.DS_Store
6+
*.iml
7+
*.apk
8+
*.aar
9+
*.zip
10+
google-services.json

auth/.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

auth/app/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

auth/app/build.gradle

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.1"
6+
defaultConfig {
7+
applicationId "com.google.firebase.quickstart.auth"
8+
minSdkVersion 14
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile 'com.android.support:appcompat-v7:25.1.0'
23+
compile 'com.google.firebase:firebase-auth:10.0.1'
24+
}

auth/app/proguard-rules.pro

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /usr/local/google/home/samstern/android-sdk-linux/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}

auth/app/src/main/AndroidManifest.xml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.google.firebase.quickstart.auth">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN" />
14+
15+
<category android:name="android.intent.category.LAUNCHER" />
16+
</intent-filter>
17+
</activity>
18+
</application>
19+
20+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
package com.google.firebase.quickstart.auth;
2+
3+
import android.net.Uri;
4+
import android.os.Bundle;
5+
import android.support.annotation.NonNull;
6+
import android.support.v7.app.AppCompatActivity;
7+
import android.util.Log;
8+
import android.widget.Toast;
9+
10+
import com.google.android.gms.tasks.OnCompleteListener;
11+
import com.google.android.gms.tasks.Task;
12+
import com.google.firebase.auth.AuthCredential;
13+
import com.google.firebase.auth.AuthResult;
14+
import com.google.firebase.auth.EmailAuthProvider;
15+
import com.google.firebase.auth.FirebaseAuth;
16+
import com.google.firebase.auth.FirebaseUser;
17+
import com.google.firebase.auth.GithubAuthProvider;
18+
import com.google.firebase.auth.UserInfo;
19+
import com.google.firebase.auth.UserProfileChangeRequest;
20+
21+
public class MainActivity extends AppCompatActivity {
22+
23+
private static final String TAG = "MainActivity";
24+
25+
@Override
26+
protected void onCreate(Bundle savedInstanceState) {
27+
super.onCreate(savedInstanceState);
28+
setContentView(R.layout.activity_main);
29+
}
30+
31+
private void checkCurrentUser() {
32+
// [START check_current_user]
33+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
34+
if (user != null) {
35+
// User is signed in
36+
} else {
37+
// No user is signed in
38+
}
39+
// [END check_current_user]
40+
}
41+
42+
private void getUserProfile() {
43+
// [START get_user_profile]
44+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
45+
if (user != null) {
46+
// Name, email address, and profile photo Url
47+
String name = user.getDisplayName();
48+
String email = user.getEmail();
49+
Uri photoUrl = user.getPhotoUrl();
50+
51+
// Check if user's email is verified
52+
boolean emailVerified = user.isEmailVerified();
53+
54+
// The user's ID, unique to the Firebase project. Do NOT use this value to
55+
// authenticate with your backend server, if you have one. Use
56+
// FirebaseUser.getToken() instead.
57+
String uid = user.getUid();
58+
}
59+
// [END get_user_profile]
60+
}
61+
62+
private void getProviderData() {
63+
// [START get_provider_data]
64+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
65+
if (user != null) {
66+
for (UserInfo profile : user.getProviderData()) {
67+
// Id of the provider (ex: google.com)
68+
String providerId = profile.getProviderId();
69+
70+
// UID specific to the provider
71+
String uid = profile.getUid();
72+
73+
// Name, email address, and profile photo Url
74+
String name = profile.getDisplayName();
75+
String email = profile.getEmail();
76+
Uri photoUrl = profile.getPhotoUrl();
77+
};
78+
}
79+
// [END get_provider_data]
80+
}
81+
82+
private void updateProfile() {
83+
// [START update_profile]
84+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
85+
86+
UserProfileChangeRequest profileUpdates = new UserProfileChangeRequest.Builder()
87+
.setDisplayName("Jane Q. User")
88+
.setPhotoUri(Uri.parse("https://example.com/jane-q-user/profile.jpg"))
89+
.build();
90+
91+
user.updateProfile(profileUpdates)
92+
.addOnCompleteListener(new OnCompleteListener<Void>() {
93+
@Override
94+
public void onComplete(@NonNull Task<Void> task) {
95+
if (task.isSuccessful()) {
96+
Log.d(TAG, "User profile updated.");
97+
}
98+
}
99+
});
100+
// [END update_profile]
101+
}
102+
103+
private void updateEmail() {
104+
// [START update_email]
105+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
106+
107+
user.updateEmail("[email protected]")
108+
.addOnCompleteListener(new OnCompleteListener<Void>() {
109+
@Override
110+
public void onComplete(@NonNull Task<Void> task) {
111+
if (task.isSuccessful()) {
112+
Log.d(TAG, "User email address updated.");
113+
}
114+
}
115+
});
116+
// [END update_email]
117+
}
118+
119+
private void updatePassword() {
120+
// [START update_password]
121+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
122+
String newPassword = "SOME-SECURE-PASSWORD";
123+
124+
user.updatePassword(newPassword)
125+
.addOnCompleteListener(new OnCompleteListener<Void>() {
126+
@Override
127+
public void onComplete(@NonNull Task<Void> task) {
128+
if (task.isSuccessful()) {
129+
Log.d(TAG, "User password updated.");
130+
}
131+
}
132+
});
133+
// [END update_password]
134+
}
135+
136+
private void sendPasswordReset() {
137+
// [START send_password_reset]
138+
FirebaseAuth auth = FirebaseAuth.getInstance();
139+
String emailAddress = "[email protected]";
140+
141+
auth.sendPasswordResetEmail(emailAddress)
142+
.addOnCompleteListener(new OnCompleteListener<Void>() {
143+
@Override
144+
public void onComplete(@NonNull Task<Void> task) {
145+
if (task.isSuccessful()) {
146+
Log.d(TAG, "Email sent.");
147+
}
148+
}
149+
});
150+
// [END send_password_reset]
151+
}
152+
153+
private void deleteUser() {
154+
// [START delete_user]
155+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
156+
157+
user.delete()
158+
.addOnCompleteListener(new OnCompleteListener<Void>() {
159+
@Override
160+
public void onComplete(@NonNull Task<Void> task) {
161+
if (task.isSuccessful()) {
162+
Log.d(TAG, "User account deleted.");
163+
}
164+
}
165+
});
166+
// [END delete_user]
167+
}
168+
169+
private void reauthenticate() {
170+
// [START reauthenticate]
171+
FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser();
172+
173+
// Get auth credentials from the user for re-authentication. The example below shows
174+
// email and password credentials but there are multiple possible providers,
175+
// such as GoogleAuthProvider or FacebookAuthProvider.
176+
AuthCredential credential = EmailAuthProvider
177+
.getCredential("[email protected]", "password1234");
178+
179+
// Prompt the user to re-provide their sign-in credentials
180+
user.reauthenticate(credential)
181+
.addOnCompleteListener(new OnCompleteListener<Void>() {
182+
@Override
183+
public void onComplete(@NonNull Task<Void> task) {
184+
Log.d(TAG, "User re-authenticated.");
185+
}
186+
});
187+
// [END reauthenticate]
188+
}
189+
190+
private void authWithGithub() {
191+
FirebaseAuth mAuth = FirebaseAuth.getInstance();
192+
193+
// [START auth_with_github]
194+
String token = "<GITHUB-ACCESS-TOKEN>";
195+
AuthCredential credential = GithubAuthProvider.getCredential(token);
196+
mAuth.signInWithCredential(credential)
197+
.addOnCompleteListener(this, new OnCompleteListener<AuthResult>() {
198+
@Override
199+
public void onComplete(@NonNull Task<AuthResult> task) {
200+
Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful());
201+
202+
// If sign in fails, display a message to the user. If sign in succeeds
203+
// the auth state listener will be notified and logic to handle the
204+
// signed in user can be handled in the listener.
205+
if (!task.isSuccessful()) {
206+
Log.w(TAG, "signInWithCredential", task.getException());
207+
Toast.makeText(MainActivity.this, "Authentication failed.",
208+
Toast.LENGTH_SHORT).show();
209+
}
210+
211+
// ...
212+
}
213+
});
214+
// [END auth_with_github]
215+
}
216+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent"
6+
android:paddingBottom="@dimen/activity_vertical_margin"
7+
android:paddingLeft="@dimen/activity_horizontal_margin"
8+
android:paddingRight="@dimen/activity_horizontal_margin"
9+
android:paddingTop="@dimen/activity_vertical_margin"
10+
tools:context="com.google.firebase.quickstart.auth.MainActivity">
11+
12+
<TextView
13+
android:layout_width="wrap_content"
14+
android:layout_height="wrap_content"
15+
android:text="Hello World!" />
16+
</RelativeLayout>
Loading
Loading
Loading
Loading
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<resources>
2+
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
3+
(such as screen margins) for screens with more than 820dp of available width. This
4+
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
5+
<dimen name="activity_horizontal_margin">64dp</dimen>
6+
</resources>
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
<color name="colorPrimary">#3F51B5</color>
4+
<color name="colorPrimaryDark">#303F9F</color>
5+
<color name="colorAccent">#FF4081</color>
6+
</resources>
+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<resources>
2+
<!-- Default screen margins, per the Android Design guidelines. -->
3+
<dimen name="activity_horizontal_margin">16dp</dimen>
4+
<dimen name="activity_vertical_margin">16dp</dimen>
5+
</resources>
+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<resources>
2+
<string name="app_name">auth</string>
3+
</resources>
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<resources>
2+
3+
<!-- Base application theme. -->
4+
<style name="AppTheme" parent="Theme.AppCompat">
5+
<!-- Customize your theme here. -->
6+
<item name="colorPrimary">@color/colorPrimary</item>
7+
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
8+
<item name="colorAccent">@color/colorAccent</item>
9+
</style>
10+
11+
</resources>

auth/build.gradle

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Top-level build file where you can add configuration options common to all sub-projects/modules.
2+
3+
buildscript {
4+
repositories {
5+
jcenter()
6+
}
7+
dependencies {
8+
classpath 'com.android.tools.build:gradle:2.2.3'
9+
10+
// NOTE: Do not place your application dependencies here; they belong
11+
// in the individual module build.gradle files
12+
}
13+
}
14+
15+
allprojects {
16+
repositories {
17+
mavenLocal()
18+
jcenter()
19+
}
20+
}
21+
22+
task clean(type: Delete) {
23+
delete rootProject.buildDir
24+
}

auth/gradle.properties

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true
52.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)