Using Oauth to connect a Java application with a G

2019-06-08 05:50发布

I have a Java application and a GAE application, that sends C2DM messages to Android devices.

Now I would like to make the users of the java application able to sign in via their Google accounts to the GAE application. Am I correct, that I need to use oauth to realize this?

A litte bit of background:

+-----------+                        +----------+
| JAVA App  |  send Message to --->  | GAE App  | 
+-----------+                        +----------+
  ^                                         |
  | Notify Client                           |
  ---------------------------- <User is allowed to send>
                                            |
                                            |
                                          [YES] ---> Start delivering C2DMessage

I hope my great ASCII picture make it easier to understand ;)

Somehow I need to allow the user to login in the java application with their google credentials and if I send a message to the server the user data is being sent with the message to the server.

I do not really have an idea how to do this. It would be great, if you could tell me, wheter I am on the right or wrong track. I would be really glad for any suggestions.

Thanks, Mark

2条回答
Fickle 薄情
2楼-- · 2019-06-08 06:42

If you're going to use GAE, instead of using OAuth, why not use the Users API?

http://code.google.com/appengine/docs/java/users/

查看更多
Lonely孤独者°
3楼-- · 2019-06-08 06:55

OAuth is used when your application need to access resources or perform operation on another service on the behalf of the user (without needing their credentials).

Depending on what is your Java application (desktop, web, mobile), you will use different OAuth flow as shown in the Auth documentation for Google APIs.

And no need for the user to login in the Java application, as long as they are logged in the GAE application, you should be able to retrieve an Access Token from GAE OAuth end points.

Note that GAE only support OAuth 1.0, when acting as an OAuth provider, see the GAE OAuth Documentation for more details.

Also Ikai recently made a blog post detailing how to setup a OAuth provider on GAE/Java.

As a side note, did you take a look at the latest GPE version, it features tooling for developing Android Application with a GAE backend, as show in this year Google I/O presentation

Hope that helps.

查看更多
登录 后发表回答