A Go library for managing authentication, backed by PropelAuth.
PropelAuth makes it easy to add authentication and authorization to your B2B/multi-tenant application.
Your frontend gets a beautiful, safe, and customizable login screen. Your backend gets easy authorization with just a few lines of code. You get an easy-to-use dashboard to config and manage everything.
- Sign up for a free account at Propelauth.
- Create a new project.
- Go to the Backend Integrations section in the dashboard and note the Auth URL and API Key.
Make sure you have Go version 1.20.
Make a new directory, initialize your program, and get the propelauth-go library.
mkdir propelauth-example
cd propelauth-example
go mod init propelauth-example
go get github.com/propelauth/propelauth-go
Create a file that looks like this.
package main
import (
"os"
"fmt"
propelauth "github.com/propelauth/propelauth-go/pkg"
models "github.com/propelauth/propelauth-go/pkg/models"
)
func main() {
// initialize the client
// (you can get these variables from the Backend Integrations section on your dashboard)
apiKey := os.Getenv("PROPELAUTH_API_KEY")
authUrl := os.Getenv("PROPELAUTH_AUTH_URL")
client, err := propelauth.InitBaseAuth(authUrl, apiKey, nil)
if err != nil {
panic(err)
}
// see how many users we have now
queryParams := models.UserQueryParams{}
users, err := client.FetchUsersByQuery(queryParams)
if err != nil {
panic(err)
}
fmt.Printf("Found %d users\n", users.TotalUsers)
// create a new user
newUser := models.CreateUserParams{
Email: "[email protected]",
}
createdUser, err := client.CreateUser(newUser)
if err != nil {
panic(err)
}
fmt.Printf("Created a user with the ID %v\n", createdUser.UserID)
// fetch the user we just created
fetchedUser, err := client.FetchUserMetadataByUserID(createdUser.UserID, false)
if err != nil {
panic(err)
}
fmt.Printf("Found the user we just created %#v.\n", fetchedUser)
}
Set the two environment variables, PROPELAUTH_API_KEY and PROPELAUTH_AUTH_URL, with the values from the Backend Integrations section on your dashboard.
Finally, run the program.
go run .
You will see that a user was created. You can see that use in the dashboard.
Just for fun, if you run this program again, you'll get an error message saying, "An account already exists with that email address."
The PropelAuth Go SDK is released under the MIT license.
Feel free to reach out at [email protected]. We like answering questions!