# Netlify identity and go functions

**URL:** <https://answers.netlify.com/t/netlify-identity-and-go-functions/17810>\
**Category:** Support\
**Tags:** identity, lambda-functions\
**Created:** [June 27, 2020, 6:28pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810 "2020-06-27T18:28:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![okeydoke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/okeydoke/32/12536_2.png) [@okeydoke](https://answers.netlify.com/u/okeydoke)\
**Post date:** [June 27, 2020, 6:28pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/1 "2020-06-27T18:28:08Z")

</div>

netlify site name: `nervous-lewin-928377 `

This is my first time using Netlify Identity, so wanted to double check a few things. Been using the docs here as a reference [Build functions | Netlify Docs](https://docs.netlify.com/functions/build-with-go/#access-the-clientcontext). The docs made it look like you only need to check for a valid lambda context to auth the route, but I saw a valid context regardless whether or not a valid token was submitted by the front end. So wanted to double check my approach.

When I log the request context I can see some information attached by netlify in the `Custom` field (abbreviated token below). It looks something like `Custom:map[netlify:eyJpZGVudGl0eSI6....=]`

```auto
{"file":"handlers.go:38","func":"ServeHTTP","level":"info","msg":"cc: {Client:{InstallationID: AppTitle: AppVersionCode: AppPackageName:} Env:map[] Custom:map[netlify:eyJpZGVudGl0eSI6....=]}","time":"2020-06-27T07:27:32Z"}

```

I’m able to parse this `Custom` field and then check for the presence of a user. Attaching full middleware below.

> <https://github.com/mkrump/contemos/blob/7223b024f20500e99d7e6006e342f4aac3023357/api/numbers/handlers.go#L34-L91>

Everything seems to be working. Users with valid tokens are allowed to make requests and those with no token or an invalid token are not. But, just wanted to check if this all looks as expected as I was having trouble finding a complete example of auth for a netlify function on the go side.

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [July 1, 2020, 5:49pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/2 "2020-07-01T17:49:10Z")

</div>

Hi @okeydoke,

We won’t authenticate functions automatically. You can use the context to validate and then perform what you need to do in your function. Or if the token fails to validate, you can return a status code for 401, etc. Hope that makes sense.

---

<div class="post-metadata">

**Author:** ![okeydoke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/okeydoke/32/12536_2.png) [@okeydoke](https://answers.netlify.com/u/okeydoke)\
**Post date:** [July 1, 2020, 6:21pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/3 "2020-07-01T18:21:47Z")

</div>

Thanks @Dennis. Is the Bearer token the frontend provides just forwarded along to the backend via the context (with no intermediate steps)? I had read the docs / a few blog posts and was a little confused about what I needed to verify in the lambda in order to ensure that a logged in user was making the request. For example, from the blog post below:

> When your serverless function endpoint receives these new headers, _ **Netlify’s Functions service will automatically detect any bearer token and verify the signature. If it’s a valid token issued by the Identity instance linked to the site, Netlify will add the user’s claims in a `context.clientContext.user` object.** _

> **[JAMstack architecture on Netlify: How Identity and Functions work together](https://www.netlify.com/blog/2018/03/29/jamstack-architecture-on-netlify-how-identity-and-functions-work-together/)**
>
> Take a deeper look at how to use Netlify Functions together with Netlify’s Identity feature to access and update user data, and allow your users to send you a message that you receive directly on Slack. All it takes is a little bit of glue code to...

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [July 6, 2020, 5:38pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/4 "2020-07-06T17:38:51Z")

</div>

Yea, there is no intermediate steps. You provide the token and our system will do the checks. If it’s valid, you will find the claims in the context.clientContext.user object. So you could check for that object to confirm that the request is authorized. Hope that makes sense.

---

<div class="post-metadata">

**Author:** ![okeydoke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/okeydoke/32/12536_2.png) [@okeydoke](https://answers.netlify.com/u/okeydoke)\
**Post date:** [July 7, 2020, 10:50pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/5 "2020-07-07T22:50:37Z")

</div>

Thanks. But isn’t this an intermediate step between the frontend and the lambda?

> You provide the token and _ **our system will do the checks.** _

But I think that I follow.

Frontend submits a request with a token → Netlify verifies the token and if it’s valid attaches the claim to context and forwards to the Netlify function (and if token is not valid the claim is not attached to context) → Netilify function can use the info the gets attached to the context (like `user`) to allow or deny access.

---

<div class="post-metadata">

**Author:** ![Dennis](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/dennis/32/34_2.png) [@Dennis](https://answers.netlify.com/u/Dennis)\
**Post date:** [July 8, 2020, 4:59pm UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/6 "2020-07-08T16:59:06Z")

</div>

Ah, right, it is. 😃 I just meant that no intermediate step is needed to be taken by you. And your summary is correct.

---

<div class="post-metadata">

**Author:** ![okeydoke](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/okeydoke/32/12536_2.png) [@okeydoke](https://answers.netlify.com/u/okeydoke)\
**Post date:** [July 16, 2020, 2:02am UTC](https://answers.netlify.com/t/netlify-identity-and-go-functions/17810/7 "2020-07-16T02:02:40Z")

</div>

Thanks again. For future travelers, I made an example app [go-netlify-login-example](https://github.com/mkrump/go-netlify-login-example) with everything wired up.
