aloey

aloey

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.

Showing Posts 1 to 9

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

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.

aloey

aloey OP

Thank you so much @wmnnd @MrDoops for the welcome and suggestions!

I honestly thought it was the ONLY way to implement the google sign-in, to use that “javascript-based login button” haha.

In the mean time, I have figured out that, for some reason, the backend wasn’t receiving the correct id_token that I got from the client-side, and therefore all my tokeninfo endpoint was failing. (obviously I thought it was google’s fault as should a good tunnel-visioned coder)

I will definitely check out both suggestions and see if I can get the redirect urls to work with the localhost as well (which is where im doing most of development and debugging)

Thanks again!

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).

aloey

aloey OP

@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.

benonymus

benonymus

I am in a similar situation, that I need a backend that can handle web and mobile too, so it will probably will have to be the token route, do you have any update how you did it?

sergio

sergio

Hey same here, I set up login on my single-page react web app and have the tokenId. I’m sending it to my Elixir api-only backend, but I don’t know how to fetch my Google user using this token.

const handleLogin = async (response: any) => {
    console.log(response);

    const res = await fetch("/api/v1/auth/google", {
        method: "POST",
        body: JSON.stringify({
            token: response.tokenId
        }),
        headers: {
            "Content-Type": "application/json"
        }
    })

    const data = await res.json()
    console.log(data)
}

In my backend I’m trying to figure out how to get my user information for the past couple of hours.

def google(conn, params) do
  IO.inspect params
end
sergio

sergio

I believe I figured it out! Of course the second I ask about it I answer myself as usual haha!

Guide incoming for would-be googlers.

shiroyasha

shiroyasha

I’m one of those googlers :sweat_smile:

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

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
Onor.io
I have what I’ve heard referred to as a “lookup table” in my database. This is a way of assigning codes to common values. One common lo...
New
Trolleger
What approach to take when sending live updates to “random” users Hi! I have a question, I have a little chat app, and when I create a DM...
New
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New

Other Trending Topics Top

garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
wintermeyer
There are three potential reasons for members of this forum to have a look at https://vutuv.de You are tired or annoyed of LinkedIn. Yo...
New
webofbits
Aludel - LLM Evaluation Workbench Aludel is an embeddable Phoenix LiveView dashboard for evaluating and comparing LLM prompts across mult...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews