Coder Social home page Coder Social logo

Access token for Cloud Function about goth HOT 14 CLOSED

paveltyk avatar paveltyk commented on September 26, 2024
Access token for Cloud Function

from goth.

Comments (14)

paveltyk avatar paveltyk commented on September 26, 2024 1

@krishandley Yes, that sounds right. Those claims will be passed to individual GenServers managed by Goth.

from goth.

wojtekmach avatar wojtekmach commented on September 26, 2024

This is currently not possible, we're missing ability to pass target_audience parameter when generating the JWT token. See #58. If you'd like to explore this further and send a PR, it will be very appreciated but we don't have plans to add it ourselves at the moment. Thanks!

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

Thank you for a quick reply. If I go for a PR, should I start with v1.3.0 ?

from goth.

wojtekmach avatar wojtekmach commented on September 26, 2024

yeah, please open against the master branch which will become 1.3.0.

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

@wojtekmach I've looked at the codebase and my suggestion would be to introduce the claims override/extends to the source config, which would require replacing sub option to be replaced with claims: %{"sub" => "[email protected]"}, i.e. Goth.start_link(name: MyApp.Goth, source: {:service_account, credentials, [sub: "[email protected]"]}) will become Goth.start_link(name: MyApp.Goth, source: {:service_account, credentials, [claims: %{"sub" => "[email protected]"}]}).

Then they will be merged in JWT.

Let me know if you foresee any issues with that approach. Otherwise I will build a PR. Thank you.

Regards,
Pavel.

from goth.

wojtekmach avatar wojtekmach commented on September 26, 2024

sounds good! Btw, I just pushed an update to docs so make sure you pull before you work on a patch.

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

@wojtekmach Any estimates on merging #102 ?

from goth.

wojtekmach avatar wojtekmach commented on September 26, 2024

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

To sum up: As I figured out, even though Google docs ask for a target_audience param to generate cloud function invocation token, it works fine if I submit cloud function URL as a scope instead. Therefore it's possible to get a token ID for cloud function with v1.3.0 and PR #102. The config looks like this: %{source: {:service_account, credentials, scopes: [cloud_function_url]}}

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

@wojtekmach PR #102 and a little trick around scope vs target_audience allow to get cloud function invocation token. However there still room for improvement. Should I go for my previous proposal to add claims in a source config ({:service_account, credentials, [sub: "[email protected]"]} => {:service_account, credentials, [claims: %{"sub" => "[email protected]"}]}) ? That should address all possible edge cases if one needed.

from goth.

wojtekmach avatar wojtekmach commented on September 26, 2024

Yeah a more general solution is definitely welcome. Please remember to revert parts of the previous PR if they no longer make sense.

from goth.

krishandley avatar krishandley commented on September 26, 2024

Sorry to bother you, just writing this in case you happen to know. This did work initially when I had one function.

Maybe I'm doing something wrong, but doesn't seem to work if you have two functions. Adding multiple function urls to the scopes breaks all of them.

I can add Goth multiple times with different ID's to my supervision tree, I don't know if that's a terrible idea or not, but it works.

from goth.

paveltyk avatar paveltyk commented on September 26, 2024

@krishandley since #102 has been merged in master maybe try the master branch with the claims approach? I do not remember it on top of my head, but try something like:

Goth.start_link(
  name: MyApp.Goth,
  source: {
    :service_account,
    credentials,
    [
      claims: %{
        "sub" => "[email protected]",
        "target_audience" => "URL HERE"
      }
    ]
  }
)

from goth.

krishandley avatar krishandley commented on September 26, 2024

@paveltyk Thanks for the quick reply. I missed the updated docs for Goth.Token on master.

I wasn't able to figure out the config for multiple functions inside start_link. But calling this before calling a function worked, without needing the claims in the config.

Goth.Token.fetch(%{
  source: {:service_account, credentials, [
    claims: %{"target_audience" => function_url}
  ]}
})

from goth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.