Skip to content

Commit

Permalink
Rename repo to auth-go (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwoodhouse93 authored Sep 8, 2024
1 parent 9f8e4dc commit c4770b9
Show file tree
Hide file tree
Showing 45 changed files with 127 additions and 114 deletions.
61 changes: 35 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
# gotrue-go
# auth-go

![example branch parameter](https://github.com/supabase-community/gotrue-go/actions/workflows/test.yaml/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/supabase-community/gotrue-go/branch/main/graph/badge.svg?token=JQQJKETMRX)](https://codecov.io/gh/supabase-community/gotrue-go)
![GitHub](https://img.shields.io/github/license/supabase-community/gotrue-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/supabase-community/gotrue-go.svg)](https://pkg.go.dev/github.com/supabase-community/gotrue-go)
![example branch parameter](https://github.com/supabase-community/auth-go/actions/workflows/test.yaml/badge.svg?branch=main)
[![codecov](https://codecov.io/gh/supabase-community/auth-go/branch/main/graph/badge.svg?token=JQQJKETMRX)](https://codecov.io/gh/supabase-community/auth-go)
![GitHub](https://img.shields.io/github/license/supabase-community/auth-go)
[![Go Reference](https://pkg.go.dev/badge/github.com/supabase-community/auth-go.svg)](https://pkg.go.dev/github.com/supabase-community/auth-go)

A Golang client library for the [Supabase Auth](https://github.com/supabase/auth) API.

A Golang client library for the [Supabase GoTrue](https://github.com/supabase/gotrue) API.

> ⚠️ Using [`netlify/gotrue`](https://github.com/netlify/gotrue)?
>
> The types in this library assume you are interacting with a Supabase GoTrue server. It is very unlikely to work with a Netlify GoTrue server.
For more information about the Supabase fork of GoTrue, [check out the project here](https://github.com/supabase/gotrue).
For more information about the Supabase fork of GoTrue, [check out the project here](https://github.com/supabase/auth).

## Project status

Expand All @@ -25,14 +20,15 @@ The endpoints for SSO SAML are not tested and `POST /sso/saml/acs` does not prov
### Install

```sh
go get github.com/supabase-community/gotrue-go
go get github.com/supabase-community/auth-go
```

### Usage

```go
package main

import "github.com/supabase-community/gotrue-go"
import "github.com/supabase-community/auth-go"

const (
projectReference = "<your_supabase_project_reference>"
Expand All @@ -41,13 +37,13 @@ const (

func main() {
// Initialise client
client := gotrue.New(
client := auth.New(
projectReference,
apiKey,
)

// Log in a user (get access and refresh tokens)
resp, err := client.Token(gotrue.TokenRequest{
resp, err := client.Token(auth.TokenRequest{
GrantType: "password",
Email: "<user_email>",
Password: "<user_password>",
Expand All @@ -66,12 +62,12 @@ The client can be customized with the options below.
In all cases, **these functions return a copy of the client**. To use the configured value, you must use the returned client. For example:

```go
client := gotrue.New(
client := auth.New(
projectRefernce,
apiKey,
)

token, err := client.Token(gotrue.TokenRequest{
token, err := client.Token(auth.TokenRequest{
GrantType: "password",
Email: email,
Password: password,
Expand All @@ -90,39 +86,52 @@ if err != nil {
```

### WithToken

```go
func (*Client) WithToken(token string) *Client
```

Returns a client that will use the provided token in the `Authorization` header on all requests.

### WithCustomGoTrueURL
### WithCustomAuthURL

```go
func (*Client) WithCustomGoTrueURL(url string) *Client
func (*Client) WithCustomAuthURL(url string) *Client
```

Returns a client that will use the provided URL instead of `https://<project_ref>.supabase.com/auth/v1/`. This allows you to use the client with your own deployment of the GoTrue server without relying on a Supabase-hosted project.
Returns a client that will use the provided URL instead of `https://<project_ref>.supabase.com/auth/v1/`. This allows you to use the client with your own deployment of the Auth server without relying on a Supabase-hosted project.

### WithClient

```go
func (*Client) WithClient(client http.Client) *Client
```

By default, the library uses a default http.Client. If you want to configure your own, pass one in using `WithClient` and it will be used for all requests made with the returned `*gotrue.Client`.
By default, the library uses a default http.Client. If you want to configure your own, pass one in using `WithClient` and it will be used for all requests made with the returned `*auth.Client`.

## Testing

> You don't need to know this stuff to use the library

The library is tested against a real GoTrue server running in a docker image. This also requires a postgres server to back it. These are configured using docker compose.
The library is tested against a real Auth server running in a docker image. This also requires a postgres server to back it. These are configured using docker compose.

To run these tests, simply `make test`.

To interact with docker compose, you can also use `make up` and `make down`.

## Differences from gotrue-js
## Differences from auth-js

Prior users of [`auth-js`](https://github.com/supabase/auth-js) may be familiar with its subscription mechanism and session management - in line with its ability to be used as a client-side authentication library, in addition to use on the server.

As Go is typically used on the backend, this library acts purely as a convenient wrapper for interacting with a Auth server. It provides no session management or subscription mechanism.

## Migrating from gotrue-go

This repository was created as a duplicate of [gotrue-go](https://github.com/supabase-community/gotrue-go).

Prior users of [`gotrue-js`](https://github.com/supabase/gotrue-js) may be familiar with its subscription mechanism and session management - in line with its ability to be used as a client-side authentication library, in addition to use on the server.
As part of renaming the package, breaking changes to the API were also introduced, to keep consistency with the new naming. The changes can generally be boiled down to:

As Go is typically used on the backend, this library acts purely as a convenient wrapper for interacting with a GoTrue server. It provides no session management or subscription mechanism.
1. Rename instances of `gotrue-go` to `auth-go`
2. Rename instances of `GoTrue` to `Auth`

There are a small number of exceptions where required to maintain compatibility with the implementation of the Auth server. No other changes were introduced, so you should find the exact same functionality under a very similar name if updating your codebase from gotrue-go to auth-go.
20 changes: 10 additions & 10 deletions api.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package gotrue
package auth

import (
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

// Create a new client using gotrue.New, then you can call the methods below.
// Create a new client using auth.New, then you can call the methods below.
//
// Some methods require bearer token authentication. To set the bearer token,
// use the WithToken(token) method.
Expand All @@ -15,15 +15,15 @@ type Client interface {
// Options:

// By default, the client will use the supabase project reference and assume
// you are connecting to the GoTrue server as part of a supabase project.
// To connect to a GoTrue server hosted elsewhere, you can specify a custom
// you are connecting to the Auth server as part of a supabase project.
// To connect to a Auth server hosted elsewhere, you can specify a custom
// URL using this method.
//
// It returns a copy of the client, so only requests made with the returned
// copy will use the new URL.
//
// This method does not validate the URL you pass in.
WithCustomGoTrueURL(url string) Client
WithCustomAuthURL(url string) Client
// WithToken sets the access token to pass when making admin requests that
// require token authentication.
//
Expand Down Expand Up @@ -164,7 +164,7 @@ type Client interface {

// GET /health
//
// Check the health of the GoTrue server.
// Check the health of the Auth server.
HealthCheck() (*types.HealthCheckResponse, error)

// POST /invite
Expand Down Expand Up @@ -217,7 +217,7 @@ type Client interface {

// GET /settings
//
// Returns the publicly available settings for this gotrue instance.
// Returns the publicly available settings for this auth instance.
GetSettings() (*types.SettingsResponse, error)

// POST /signup
Expand Down Expand Up @@ -294,7 +294,7 @@ type Client interface {
// provided for convenience and will simply POST your HTTP request to the
// endpoint and return the response.
//
// For required parameters, see the SAML spec or the GoTrue implementation
// For required parameters, see the SAML spec or the Auth implementation
// of this endpoint.
//
// The server may issue redirects. Using the default HTTP client, this method
Expand All @@ -317,7 +317,7 @@ type Client interface {
// If successful, the server returns a redirect to the provider's authorization
// URL. The client will follow it and return the final HTTP response.
//
// GoTrue allows you to skip following the redirect by setting SkipHTTPRedirect
// Auth allows you to skip following the redirect by setting SkipHTTPRedirect
// on the request struct. In this case, the URL to redirect to will be returned
// in the response.
SSO(req types.SSORequest) (*types.SSOResponse, error)
Expand Down
14 changes: 7 additions & 7 deletions client.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package gotrue
package auth

import (
"errors"
"net/http"

"github.com/supabase-community/gotrue-go/endpoints"
"github.com/supabase-community/auth-go/endpoints"
)

var (
ErrInvalidProjectReference = errors.New("cannot create gotrue client: invalid project reference")
ErrInvalidProjectReference = errors.New("cannot create auth client: invalid project reference")
)

var _ Client = &client{}
Expand All @@ -17,13 +17,13 @@ type client struct {
*endpoints.Client
}

// Set up a new GoTrue client.
// Set up a new Auth client.
//
// projectReference: The project reference is the unique identifier for your
// Supabase project. It can be found in the Supabase dashboard under project
// settings as Reference ID.
//
// apiKey: The API key is used to authenticate requests to the GoTrue server.
// apiKey: The API key is used to authenticate requests to the Auth server.
// This should be your anon key.
//
// This function does not validate your project reference. Requests will fail
Expand All @@ -34,9 +34,9 @@ func New(projectReference string, apiKey string) Client {
}
}

func (c client) WithCustomGoTrueURL(url string) Client {
func (c client) WithCustomAuthURL(url string) Client {
return &client{
Client: c.Client.WithCustomGoTrueURL(url),
Client: c.Client.WithCustomAuthURL(url),
}
}

Expand Down
2 changes: 1 addition & 1 deletion endpoints/adminaudit.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/tomnomnom/linkheader"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const adminAuditPath = "/admin/audit"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/admingeneratelink.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const adminGenerateLinkPath = "/admin/generate_link"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/adminssoproviders.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const adminSSOPath = "/admin/sso/providers"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/adminusers.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const adminUsersPath = "/admin/users"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/adminusersfactors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

// GET /admin/users/{user_id}/factors
Expand Down
2 changes: 1 addition & 1 deletion endpoints/authorize.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const authorizePath = "/authorize"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func New(projectReference string, apiKey string) *Client {
}
}

func (c Client) WithCustomGoTrueURL(url string) *Client {
func (c Client) WithCustomAuthURL(url string) *Client {
return &Client{
client: c.client,
baseURL: url,
Expand Down
2 changes: 1 addition & 1 deletion endpoints/factors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"github.com/google/uuid"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const factorsPath = "/factors"
Expand Down
4 changes: 2 additions & 2 deletions endpoints/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

var healthPath = "/health"

// GET /health
//
// Check the health of the GoTrue server.
// Check the health of the Auth server.
func (c *Client) HealthCheck() (*types.HealthCheckResponse, error) {
r, err := c.newRequest(healthPath, http.MethodGet, nil)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion endpoints/invite.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const invitePath = "/invite"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/magiclink.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const magiclinkPath = "/magiclink"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/otp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const otpPath = "/otp"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/recover.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"io"
"net/http"

"github.com/supabase-community/gotrue-go/types"
"github.com/supabase-community/auth-go/types"
)

const recoverPath = "/recover"
Expand Down
2 changes: 1 addition & 1 deletion endpoints/saml.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (c *Client) SAMLMetadata() ([]byte, error) {
// provided for convenience and will simply POST your HTTP request to the
// endpoint and return the response.
//
// For required parameters, see the SAML spec or the GoTrue implementation
// For required parameters, see the SAML spec or the Auth implementation
// of this endpoint.
//
// The server may issue redirects. Using the default HTTP client, this method
Expand Down
Loading

0 comments on commit c4770b9

Please sign in to comment.