Skip to content

Instantly share code, notes, and snippets.

@cyantarek
Last active May 7, 2019 11:58
Show Gist options
  • Save cyantarek/3c83951f1a66d43abd4a89a83117e40a to your computer and use it in GitHub Desktop.
Save cyantarek/3c83951f1a66d43abd4a89a83117e40a to your computer and use it in GitHub Desktop.
http.HandleFunc("/credentials", func(w http.ResponseWriter, r *http.Request) {
domain := r.Header.Get("DOMAIN")
if domain == "" {
http.Error(w, "domain missing", 500)
return
}
clientId := genKey()
clientSecret := genKey()
err := clientStore.Set(clientId, &models.Client{
ID: clientId,
Secret: clientSecret,
Domain: domain,
})
if err != nil {
http.Error(w, err.Error(), 500)
return
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(map[string]string{"client_id": clientId, "client_secret": clientSecret})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment