What is event.context.graphcool.pat? How can I acc...
# prisma-whats-new
l
What is event.context.graphcool.pat? How can I access my actual tokens from within functions?
So the pat is temporary for a function instance...I just need access to my actually created tokens
a
Which token do you want to access?
l
I have a token called:
cloudFunctionsRootToken
a
You're using the Framework Preview right?
l
Yes I believe so, I have an ejected project and I'm using the beta...
a
Yes, that's what I meant
If you specify a rootToken for a function in your project file, you will get that specific token in your context.
l
I see
a
By the way, use event.context.graphcool.rootToken, pat will be deprecated
l
Documentation for the rootToken yml?
a
If you don't specify a rootToken for your function, you will get an automatically generated one
l
So if I specify it, I can use event.context.graphcool.rootToken?
a
In both cases, you can use e.c.g.rootToken yes
In most cases, you don't have to specify it though. What would be your use case for using a named token?
l
I need the same rootToken across function instances and different functions, because I'm using the tokens as secret keys for signing JWTs
I sign in one function and then verify in another function
a
Great use case
l
So how would I specify the rootToken here:
Copy code
assignment-lti-grade:
        handler:
            code:
                src: ./functions/assignment-lti-grade/assignment-lti-grade.ts
        type: resolver
        schema: ./functions/assignment-lti-grade/assignment-lti-grade.graphql
Sorry, I'm just wondering where to put that in the yml
a
Trying to find the docs for you...
Copy code
functions:
  authenticteCustomer:
    handler:
      code:
        src: ./code/authenticate.js
    context:
      rootToken: authenticate
    type: schemaExtension
    schema: ./code/authenticate.graphql

rootTokens:
- authenticate
This should work
But you're right about the schema, so now I'm starting to have doubts whether that's actually already implemented like this...
l
I think it's working, I'll let you know
👍🏻 1
a
l
So it doesn't seem to be working
Here's my function definition:
Copy code
assignment-lti-launch:
        handler:
            code:
                src: ./functions/assignment-lti-launch/assignment-lti-launch.ts
                environment:
                    PRENDUS_LTI_SECRET: ${env:PRENDUS_LTI_SECRET}
                    PRENDUS_CLIENT_ORIGIN: ${env:PRENDUS_CLIENT_ORIGIN}
                    PRENDUS_CLIENT_DOMAIN: ${env:PRENDUS_CLIENT_DOMAIN}
        context:
            rootToken: cloudFunctionsRootToken
        type: resolver
        schema: ./functions/assignment-lti-launch/assignment-lti-launch.graphql
    assignment-lti-grade:
        handler:
            code:
                src: ./functions/assignment-lti-grade/assignment-lti-grade.ts
        context:
            rootToken: cloudFunctionsRootToken
        type: resolver
        schema: ./functions/assignment-lti-grade/assignment-lti-grade.graphql
I've run both functions, and compared their rootTokens
Both of the rootTokens are different
n
specific root tokens cannot be defined for functions at the moment
l
Oh
n
functions obtain a shortlived token automatically
a
Thanks for chiming in @nilan
n
soon it'll be possible to disable this
a
Does that also apply to the old method?
n
or refer to a specific token
a
Token with function name?
n
what I said is true for all functions, old or new
a
So that's a breaking regression?
Anyways, that's beyond the topic of this thread, I'll PM
l
👍🏻 1
Thanks for all of the help @nilan @agartha
👍🏻 1
a
I'm sorry for the confusion, the link I sent before to the other issue gave me the impression it was already working like this.
🙂 1
t
What is the use case to disable or add a specific token? @nilan
a
@Tavo Adding a specific token is mostly relevant when you either have two functions that need the same token (like @lastmjs described above), or if you use a webhook that expects a specific token (shared secret approach). Disabling might be useful if you don't want to send a rootToken to an external webhook that you specify.
t
@agartha thanks for the reply, correct me if I’m wrong but a rootToken is a token where you get from another service to interact with that service in a graphcool function and PAT is a token to interact with graphcool’s server
a
No rootToken == pat, the terminology changed a bit. Both are full API access tokens to access your Graphcool endpoints from a function.
t
Both are full API access tokens? I thought those tokens are created automatically when the function starts?