# Golang management APIs for authentication

**URL:** <https://community.auth0.com/t/golang-management-apis-for-authentication/71520>\
**Category:** Get Help\
**Created:** [October 18, 2021, 4:30pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520 "2021-10-18T16:30:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JumpC](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jumpc/32/14589_2.png) [@JumpC](https://community.auth0.com/u/JumpC)\
**Post date:** [October 18, 2021, 4:30pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520/1 "2021-10-18T16:30:54Z")

</div>

Is there a management API module/package for Golang? Something like the authenticationClient/databaseAuthenticator to authenticate a user. If not, what is the other way to do it with GO?

My backend app in GO needs to authenticate a user using username and password.

Thanks.

---

<div class="post-metadata">

**Author:** ![dan.woda](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/dan.woda/32/18340_2.png) [@dan.woda](https://community.auth0.com/u/dan.woda)\
**Post date:** [October 18, 2021, 7:23pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520/3 "2021-10-18T19:23:36Z")

</div>

Hi @JumpC ,

Welcome to the Auth0 Community!

> [@JumpC](#):
>
> Is there a management API module/package for Golang?

Yes, available here:

> **[GitHub - go-auth0/auth0: ARCHIVED Go SDK for the Auth0 platform. This project...](https://github.com/go-auth0/auth0)**
>
> ARCHIVED Go SDK for the Auth0 platform. This project is now being maintained at: https://github.com/auth0/go-auth0 - GitHub - go-auth0/auth0: ARCHIVED Go SDK for the Auth0 platform. This project is...

Let me know if you have questions about it.

> [@JumpC](#):
>
> My backend app in GO needs to authenticate a user using username and password.

In order to exchange a username/password directly for a token you will need to use the [Resource Owner Password Flow](https://auth0.com/docs/authorization/flows/resource-owner-password-flow).

---

<div class="post-metadata">

**Author:** ![JumpC](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jumpc/32/14589_2.png) [@JumpC](https://community.auth0.com/u/JumpC)\
**Post date:** [October 18, 2021, 10:27pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520/4 "2021-10-18T22:27:06Z")

</div>

Thanks for the message, Dan!

I tried the resource owner password flow and I got “unauthorized” error:

2021/10/18 22:24:27 &{401 Unauthorized 401 HTTP/2.0 2 0 map[Alt-Svc:[h3=“:443”; ma=86400, h3-29=“:443”; ma=86400, h3-28=“:443”; ma=86400, h3-27=“:443”; ma=86400] Cache-Control:[private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0, no-transform] Cf-Cache-Status:[DYNAMIC] Cf-Ray:[6a052d490f531c79-SJC] Content-Length:[60] Content-Type:[application/json] Date:[Mon, 18 Oct 2021 22:24:27 GMT] Expect-Ct:[max-age=604800, report-uri=“[https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct](https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct)”] Ot-Baggage-Auth0-Request-Id:[6a052d490f531c79] Ot-Tracer-Sampled:[true] Ot-Tracer-Spanid:[17b3c8a3580e00d5] Ot-Tracer-Traceid:[63e0275924b52f00] Server:[cloudflare] Set-Cookie:[did=s%3Av0%3A27ad9ba0-3062-11ec-8c50-c14074eae744.SibT2JNYnSS5JMuW9XQ6I4DZyW8BvfM0BlMsfOKrSR4; Max-Age=31557600; Path=/; Expires=Wed, 19 Oct 2022 04:24:27 GMT; HttpOnly; Secure; SameSite=None did\_compat=s%3Av0%3A27ad9ba0-3062-11ec-8c50-c14074eae744.SibT2JNYnSS5JMuW9XQ6I4DZyW8BvfM0BlMsfOKrSR4; Max-Age=31557600; Path=/; Expires=Wed, 19 Oct 2022 04:24:27 GMT; HttpOnly; Secure] Strict-Transport-Security:[max-age=31536000] Vary:[Origin, Accept-Encoding] X-Auth0-Requestid:[0bd6e7cca683f24fd124] X-Content-Type-Options:[nosniff] X-Ratelimit-Limit:[1000000] X-Ratelimit-Remaining:[999999] X-Ratelimit-Reset:[1634595868]] {0xc0002b69a0} 60 false false map 0xc0002a6100 0xc00028e4d0}

2021/10/18 22:24:27 {“error”:“access\_denied”,“error\_description”:“Unauthorized”}

---

<div class="post-metadata">

**Author:** ![JumpC](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jumpc/32/14589_2.png) [@JumpC](https://community.auth0.com/u/JumpC)\
**Post date:** [October 18, 2021, 10:29pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520/5 "2021-10-18T22:29:46Z")

</div>

# My code seems pretty straight forward:

```
url2 := "https://" + os.Getenv("AUTH0_DOMAIN") + "/oauth/token"

params := url.Values{}
params.Add("grant_type", "password")
params.Add("username", username)
params.Add("password", password)
params.Add("audience", os.Getenv("AUTH0_APP_API_ID"))
params.Add("scopes", "all")
params.Add("client_id", os.Getenv("AUTH0_CLIENT_ID"))
params.Add("client_secret", os.Getenv("AUTH0_CLIENT_SECRET"))

payload := strings.NewReader(params.Encode())

req, _ := http.NewRequest("POST", url2, payload)

req.Header.Add("content-type", "application/x-www-form-urlencoded")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

log.Println(res)
log.Println(string(body))

```

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 2, 2021, 10:30pm UTC](https://community.auth0.com/t/golang-management-apis-for-authentication/71520/6 "2021-11-02T22:30:45Z")

</div>

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.
