Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, 30 August 2017

Introducing Firebase Admin SDK for Go

Hiranya Jayathilaka
Hiranya Jayathilaka
Software Engineer

The Firebase Admin SDK for Go is now generally available. This is the fourth programming language to join our growing family of Admin SDKs, which already includes support for Java, Python and Node.js. Firebase Admin SDKs enable application developers to programmatically access Firebase services from trusted environments. They complement the Firebase client SDKs, which enable end users to access Firebase from their web browsers and mobile devices. The initial release of the Firebase Admin SDK for Go comes with some Firebase Authentication features: custom token minting and ID token verification.

Initializing the Admin SDK for Go

Similar to the other Firebase Admin SDKs, the Go Admin SDK can be initialized with a variety of authentication credentials and client options. The following code snippet shows how to initialize the SDK using a service account credential obtained from the Firebase console or the Google Cloud console:

import (
"golang.org/x/net/context"

firebase "firebase.google.com/go"
"google.golang.org/api/option"
)

opt := option.WithCredentialsFile("path/to/key.json")
app, err := firebase.NewApp(context.Background(), nil, opt)

If you are running your code on Google infrastructure, such as Google App Engine or Google Compute Engine, the SDK can auto-discover application default credentials from the environment. In this case you do not have to explicitly specify any credentials when initializing the Go Admin SDK:

import (
"golang.org/x/net/context"

firebase "firebase.google.com/go"
)

app, err := firebase.NewApp(context.Background(), nil)

Minting Custom Tokens and Verifying ID Tokens

The initial release of the Firebase Admin SDK for Go comes with support for minting custom tokens and verifying Firebase ID tokens. The custom token minting allows you to authenticate users using your own user store or authentication mechanism:

client, err := app.Auth()
if err != nil {
return err
}

claims := map[string]interface{}{
"premium": true,
"package": "gold",
}
token, err := client.CustomToken("some-uid", claims)

The resulting custom token can be sent to a client device, where it can be used to initiate an authentication flow using a Firebase client SDK. On the other hand, the ID token verification facilitates securely identifying the currently signed in user on your server:

client, err := app.Auth()
if err != nil {
return err
}

decoded, err := client.VerifyIDToken(idToken)
uid := decoded.UID

To learn more about using the Firebase Admin SDK for Go, see our Admin SDK setup guide.

What's Next?

We plan to further expand the capabilities of the Go Admin SDK by implementing other useful APIs such as user management and Firebase Cloud Messaging. This SDK is also open source. Therefore we welcome you to browse our Github repo and get involved in the development process by reporting issues and sending pull requests. To all Golang gophers out there, happy coding with Firebase!

Share:

Monday, 19 June 2017

Managing Users from the Firebase Admin Java SDK

Diego Giorgini
Hiranya Jayathilaka
Software Engineer


As the developer or the administrator of an app built on Firebase, you may need to perform various user management tasks. These include:

  • Provisioning new user accounts for your app
  • Updating existing user accounts
  • Manually verifying and enabling user accounts
  • Disabling or deleting user accounts
  • Querying user profile information to populate dashboards or compile reports

The Firebase Admin SDK provides a powerful API for performing these kinds of user management tasks from privileged environments. Using the Admin SDK, you can program these capabilities directly into your admin consoles, dashboards and other backend services. Unlike the Firebase client SDK, the Admin SDK is initialized with a service account credential, which grants the SDK elevated privileges necessary to perform user management operations.

This is not a brand new feature. The Firebase Admin Node.js SDK has had a user management API for a while. However, we are happy to announce that this API is now also available in our Admin Java SDK starting from version 5.1.0. This is one of the most requested features for the Admin Java SDK, and we are certain many Firebase app developers are going to find it useful.

The Java user management API closely mirrors its Node.js counterpart. Specifically, it consists of five new methods:

  • getUser()
  • getUserByEmail()
  • createUser()
  • updateUser()
  • deleteUser()

Following code snippet shows how to use some of these new methods in practice. In this example we retrieve an existing user account, and update some of its attributes:

final FirebaseAuth auth = FirebaseAuth.getInstance();
Task task = auth.getUserByEmail("editor@example.com")
.addOnSuccessListener(userRecord -> {
System.out.println("Successfully fetched user data: " + userRecord.getUid());
UpdateRequest update = userRecord.updateRequest()
.setDisabled(false) // Enable the user account
.setEmailVerified(true); // Set the email verification status
auth.updateUser(update);
})
.addOnFailureListener(e -> {
System.err.println("Error fetching user data: " + e.getMessage());
});

You can learn more about the Firebase user management API from the Admin SDK documentation. Additionally, head over to our Github repoto see how it is implemented. (Yes, it's all open source!). You can also help us further improve this API by providing us feedback and reporting issues. As always, we are open to all sorts of contributions including pull requests to our codebase. Happy coding with Firebase!

Share:

Wednesday, 5 April 2017

Bringing Firebase Admin To Python

Diego Giorgini
Hiranya Jayathilaka
Software Engineer


After announcing the Firebase Admin SDKs for Node.js and Java at the Firebase Dev Summit in Berlin last year, we received many feature requests to bring the platform to Python developers as well. Now, we're pleased to announce that first release of the Firebase Admin Python SDK, focusing on Firebase Auth token minting and verification. 

What are the Admin SDKs?


The Firebase Admin SDKs provide developers with programmatic, second-party auth access to Firebase services from trusted environments. Second-party here refers to the fact that the SDKs are granted elevated permissions that allow them to do more than a normal, untrusted client device can. The Admin SDKs get these elevated permissions since they are authenticated with a service account, a special Google account that can be used by applications to access Google services programmatically. The Admin SDKs are meant to complement the existing Firebase web and mobile clients which provide third-party, end-user access to Firebase services on client devices.


What is available in the Admin Python SDK?


As with the other Firebase Admin SDKs, the Python SDK can be initialized using a variety of built-in credential types. The following code shows how to authenticate the SDK using your own service account key file:
import firebase_admin
from firebase_admin import credentials

cred = credentials.Certificate("path/to/service.json")
firebase_admin.initialize_app(cred)

If you are running your code on Google infrastructure, such as Google App Engine or Google Compute Engine, the SDK can auto-discover the credential, allowing you to initialize the SDK with no arguments:
firebase_admin.initialize_app()

The Python Admin SDK contains Firebase Auth custom token minting and ID token verification. The custom token minting gives you complete control over authentication by allowing you to authenticate users or devices using your own authentication system.

uid = "some-uid"
additional_claims = {
"premiumAccount": True
}

custom_token = auth.create_custom_token(uid, additional_claims)

ID token verification allows you to securely identify the currently signed-in user on your server.

decoded_token = auth.verify_id_token(id_token)
uid = decoded_token["uid"]

The best place to start is with our Admin SDKs setup guide. The guide will walk you through how to download the SDK, generate a service account key file, and use that key file to initialize the Admin SDK.


What is coming next?

We plan to continue to build out the Admin Python SDK to include features already available in the other Admin SDKs, such as a user management API and an FCM API to send messages. We also plan to bring these token minting and verification features to even more languages. To see what APIs are available in each of the Admin SDKs, see our new feature matrix.

To all those Python developers out there, happy hacking!
Share:

Monday, 8 October 2012

RESTful Web Services JSON API Transformer with Java

This post is the continuation of my previous last post, I had explained how to create a basic RESTful web services API using Java, now I want to explain JSON transformer to work with input Get and Post methods parameters. Just added a new class called transformer it converts object data into JSON text output format.

RESTful Web Services with input parameters
Read more »
Share:

Sunday, 16 September 2012

RESTful Web Services API using Java and MySQL

Are you working with multiple devices like iPhone, Android and Web, then take a look at this post that explains you how to develop a RESTful API in Java. Representational state transfer (REST) is a software system for distributing the data to different kind of applications. The web service system produce status code response in JSON or XML format.

RESTful Web Services using Java and MySQL
Read more »
Share:

Monday, 27 August 2012

Java MySQL JSON Display Records using Jquery.

This is the continuation of my previous Java tutorial Insert Records into MySQL database using Jquery, now I want to explain how to convert records data into JSON data format and display JSON data feed using Jquery. It's simple just follow few steps with Eclipse IDE, hope you understand the Model View Controller pattern Thanks!

Java JSON Jquery Display Records
Read more »
Share:

Tuesday, 24 July 2012

Java MySQL Insert Record using Jquery.

If you know Java concepts, you can easily understand any kind of language very quickly. If you want to became a good programmer, I strongly suggest start with J2EE programming. I heard that many people feels that it's though After long time I decided to write about J2EE programming with Jquery in a simple and better understanding way, hope you like it. Thanks!

Menu Design with JSON Data.
Read more »
Share: