Skip to content

feat: add functions_firebase_auth #2050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions functions/snippets/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@
<version>1.19.0</version>
<scope>test</scope>
</dependency>

<!-- Required for Function primitives -->
<dependency>
<groupId>com.google.cloud.functions</groupId>
<artifactId>functions-framework-api</artifactId>
<version>1.0.0-alpha-2-rc3</version>
<type>jar</type>
</dependency>
</dependencies>

<!-- Required for Java 8 (Alpha) functions in the inline editor -->
Expand Down
38 changes: 38 additions & 0 deletions functions/snippets/src/main/java/FirebaseAuth.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2019 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// [START functions_firebase_auth]
import com.google.cloud.functions.Context;
import com.google.cloud.functions.RawBackgroundFunction;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import java.util.logging.Logger;

public class FirebaseAuth implements RawBackgroundFunction {

// Use GSON (https://github.com/google/gson) to parse JSON content.
private Gson gsonParser = new Gson();

private static final Logger LOGGER = Logger.getLogger(FirebaseAuth.class.getName());

@Override
public void accept(String json, Context context) {
JsonObject body = gsonParser.fromJson(json, JsonObject.class);
LOGGER.info("Function triggered by event: " + json);
}
}

// [END functions_firebase_auth]
5 changes: 5 additions & 0 deletions functions/snippets/src/test/java/SnippetsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,9 @@ public void helloExecutionCount() throws IOException {
new Concepts().executionCount(request, response);
assertThat(responseOut.toString(), containsString("Instance execution count: 1"));
}

@Test
public void firebaseAuth() throws IOException {
new FirebaseAuth().accept("{\"foo\": \"bar\"}", null);
}
}