-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement and test GET /reauthenticate
- Loading branch information
1 parent
d200a8f
commit 7771c77
Showing
4 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package endpoints | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
) | ||
|
||
const reauthenticatePath = "/reauthenticate" | ||
|
||
// GET /reauthenticate | ||
// | ||
// Sends a nonce to the user's email (preferred) or phone. This endpoint | ||
// requires the user to be logged in / authenticated first. The user needs to | ||
// have either an email or phone number for the nonce to be sent successfully. | ||
func (c *Client) Reauthenticate() error { | ||
r, err := c.newRequest(reauthenticatePath, http.MethodGet, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
resp, err := c.client.Do(r) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if resp.StatusCode < 200 || resp.StatusCode >= 300 { | ||
fullBody, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return fmt.Errorf("response status code %d", resp.StatusCode) | ||
} | ||
return fmt.Errorf("response status code %d: %s", resp.StatusCode, fullBody) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package integration_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kwoodhouse93/gotrue-go/types" | ||
) | ||
|
||
func TestReauthenticate(t *testing.T) { | ||
assert := assert.New(t) | ||
require := require.New(t) | ||
|
||
// User must be authenticated first | ||
err := client.Reauthenticate() | ||
assert.Error(err) | ||
|
||
client := autoconfirmClient | ||
|
||
// Create a new user | ||
email := randomEmail() | ||
session, err := client.Signup(types.SignupRequest{ | ||
Email: email, | ||
Password: "password", | ||
}) | ||
require.NoError(err) | ||
|
||
client = client.WithToken(session.AccessToken) | ||
err = client.Reauthenticate() | ||
assert.NoError(err) | ||
} |