aloey

aloey

Implementing backend authentication for google login

Hello, I have decided to learn Elixir and currently working on a simple web application using React and Phoenix. In my React app, I have a Google sign-in button that is rendered by Google’s api (Building a custom Google Sign-In button  |  Web guides  |  Google for Developers), and I am able to get the authentication response back from a successful sign in.

However, I am having a big difficulty which I have spent a few days trying to get through. I am trying to implement a backend authentication since Google suggests this (Authenticate with a backend server  |  Web guides  |  Google for Developers).

As far as I can tell, Google doesn’t seem to have an SDK for elixir and doesn’t quite go through the details on an alternative route.

I have scanned through the documentations on both ueberauth and the unofficial googleapi sdk for elixir, I was not able to find a similar function that achieves what the google documentation was describing.

I hope I have only failed to identify the functions from those libraries due to my inexperience, but I don’t mind writing from scratch if only I knew how.

Any suggestions or answers would be much appreciated and I thank you for your time and consideration in advance.

Marked As Solved

wmnnd

wmnnd

Hey there,

welcome to the Elixir Forum!

Do you absolutely want to use the JavaScript-based login button?

I haven’t tried that myself because the alternative with Ueberauth and Google Oauth2 is so simple :wink:
All you need to do is add Ueberauth to your application, configure it with your Google credentials, add the required routes and implement your authentication logic.

You should be able to get things running following the Ueberauth Google guide:

The Ueberauth devs have also created a fully configured Phoenix application using Ueberauth for further reference:

https://github.com/ueberauth/ueberauth_example

Also Liked

aloey

aloey

@wmnnd I have read and attempted to follow the ueberauth_google documentation until i saw that this library is only explaining the steps to use for a pipe_through: browser while my goal is to develop the phoenix backend that is uniformly available to support both web and mobile, and does nothing to affect the client-side.

I have a feeling this forces me to go back to using the javascript button, since if my backend is to be responsible for only validating the token returned from the google api, and not serve the html form.

I want to know what you think, and if my lack of experience made me miss something.

MrDoops

MrDoops

Try also checking out Open ID Connect and Pow Assent’s Google strategy. Depends what kind of deferred authentication you’re trying to do.

wmnnd

wmnnd

I’ve been able to do it with localhost in the past.
Alternatively, you could always set up a domain (like local.example.com with an A Record to 127.0.0.1).

Last Post!

shiroyasha

shiroyasha

I’m one of those googlers :sweat_smile:

Do you maybe still have some tips on how to approach this?

Where Next?

Popular in Questions Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
gausby
I asked this very same question on twitter and got some interesting feedback, but I thought it would be a good question to ask here as we...
1207 40165 209
New
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID<0.412.0> terminating ** (Postgrex.Error) FATAL...
New

We're in Beta

About us Mission Statement