Golang management APIs for authentication

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.

Hi @JumpC ,

Welcome to the Auth0 Community!

Yes, available here:

Let me know if you have questions about it.

In order to exchange a username/password directly for a token you will need to use the Resource Owner Password Flow.

1 Like

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”] 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”}

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

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