App Engine and API accessing contacts - google-app-engine

I have created and running an app on Google App Engine. The app has several users who log in as themself but need to use a common set of CONTACTS. ie on just one user.
When retrieving contacts how do I set the USER NAME for the set of contacts to be retrieved.
At present it always looks at the list of contacts of the user who is logged in.
I am using:
gd_client = gdata.contacts.service.ContactsService()
gdata.alt.appengine.run_on_appengine(gd_client)
query = gdata.contacts.service.ContactsQuery()
query.max_results = 10000
feed=gd_client.GetContactsFeed(query.ToUri())
for i, entry in enumerate(feed.entry):
I have the tokens stored for all users

It doesn't work that way, the user needs to grant access to your application to view the contacts in a process called OAuth2.
There is good tutorial on this here

Related

Manage two types of users FIREBASE auth + REACTJS

I'm making a system that have a users and admins, Admins could do unique things like ("delete users/access to admin dashboard ecc...").
For the frontend I'm using ReactJs, for the authentication I use firebase auth (that store the authentication info of users) and for the users data I have an Express API that saves the data in a PostgreSql db.
So when a new user is registering the email and password are saved in firebase auth, and the other data such Name,Lastname,address ecc... will be stored in PostgreSQl db where every user is identified from the unique UID that firebase provide after register.
Below a small diagram that show how the register system works
The admins will be registered manually and in PostgreSql I have a table called Admins that will store the extra data for admins (is similar of users data, but with more attributes).
But my question now is, how I check in my frontend if the current logged user is admin or normal user??
Maybe checking after login if the uid of the user logged is in the Admins postgreSql table? But this will be too expensive in terms of excecution right??? because every page reload or similar I have to repeat the check with the backend. Because firebase manage the users and admins in the same way, only my backend knows if the user is admin or not.
Anyone know if there is a good solution to handle this situation??
Thanks!
Davide.
It's probably best to use Firebase Admin's 'setCustomUserClaims' function to add to a new administrator's auth token. You could add something like "admin":true. Then, when a user authenticates, your frontend code can check if that token exists. Here's a link to Firebase's guide on doing exactly this: https://firebase.google.com/docs/auth/admin/custom-claims

server side account check - is user registered (backand.com)

i currently stuck on building an account check like whatsapp.
When a user clicks on his smartphone on his/her contacts, it should display, which user has an existing account.
So in theory it should post all user contacts to server, server checks if there is an account with this email adresse and sends the "updated list" back to the client.
Sounds easy, but how do i do something like that :)
Getting the contacts is working, also posting contacts to server.
I had my backend on backand.com and building an app with Ionic/Angular.
This should be very simple.
The core functionality here is based on Backand built in 'users' object, it holds all users you've added to your app, a simple GET to this object will return all your users details including emails.
Now you can add a serverside js action that
gets the contacts details from the client-side app in the request body (as JSON)
does an $http call to the users object ro fetch exiting users.
loops the contacts and search for them in the users array

Google Admin Sdk is not retriving all users

I using google admin sdk to get all users from domain. Below is my code
Directory.Users.List list = directoryService.users().list();
list.setCustomer("my_customer");
list.setPageToken(nextToken);
list.setMaxResults(500);
Users users = list.execute();
I found one issue today. It is not retrieving newly created users only.
I created one new user on domain and checked immediate. Above code didn't retrieve newly created user.It retrieve all old users but not new one.
I checked on Admin sdk browser, there it shows all users with newly created also.I am sure that it was retrieving all with new users before but unable to get what is happening now ? Is there any changes need to do now
for retrieving all users with new one.?

App Engine callback for new user "registration" / user login?

I'm using Google App Engine's default User service for authentication right now. I would like to be able to store the join date for a user (i.e. how long the user has been a member of my web app) and be able to ban users from my app if they misbehave.
I understand that I will need an additional model to store this information:
class User_Info(db.model):
user = db.UserProperty()
join_date = db.DateTimeProperty(auto_now_add=True)
banned = db.BooleanProperty(False)
But what I don't understand: is there a way is to get a callback for when a new user "registers" for my app (to store the join date) or logs in (to check if user has been banned)?
One method I thought of was to send in a intermediary destination URL to the users.create_login_url(), which would check if an associated User_Info instance existed. If it did, it would check the banned flag. If not, it would create a user_info instance and store the join date. It would then redirect to the actual destination url.
Is there a better solution?
Note that I will switch over to the federated authentication model in the future and was hoping for a solution that would work when I did switch over.
Thanks!
That's the right way to do it.

Should Google Appengine userId be treated as a secret?

Just wondering if the userId returned by calling the user.getUserId() should be treated as a secret, or can it be used in public URLs? for example, the profile page URLs look something like http://example.com/userprofile/11901930903930 where 11901930903930 is the Google generated userId on Appengine.
This is the function we are using to get the userId:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
String id = user.getUserId();
Actually, I found this info on Google and the conclusion is that they should not be used publicly.
From Google:
Accessing Account Information
While a user is signed in to an app, the app can access the account's email address or OpenID identifier for every request the user makes to the app. The app can also access a user ID that identifies the user uniquely, even if the user changes the email address for her account.
The app can also determine whether the current user is an administrator (a "developer") for the app. You can use this feature to build administrative features for the app, even if you don't authenticate other users. The Go, Java, and Python APIs make it easy to configure URLs as "administrator only."
Note: Every user has the same user ID for all App Engine applications. If your app uses the user ID in public data, such as by including it in a URL parameter, you should use a hash algorithm with a "salt" value added to obscure the ID. Exposing raw IDs could allow someone to associate a user's activity in one app with that in another, or get the user's email address by coercing the user to sign in to another app.
Link to page

Resources