mirror of
https://github.com/volatiletech/authboss.git
synced 2024-12-12 10:45:11 +02:00
06edd2e615
- Add a new storer specifically for OAuth2 to enable clients to choose regular database storing OR Oauth2 but not have to have both. - Stop storing OAuth2 credentials in a combined form inside username. - Add new events to capture OAuth events just like auth. - Have pass-through parameters for OAuth init urls, this allows us to pass additional behavior options (redirects and remember me) as well as other things that should be present on the page that is redirected to. - Context.LoadUser is now OAuth aware. - Remember's callbacks now include an OAuth check to see if a horribly packed state variable contains a flag to say that we want to be remembered. - Change the OAuth2 Callback to use Attributes instead of that custom struct to allow people to append whatever attributes they want into the user that will be saved.
46 lines
904 B
Go
46 lines
904 B
Go
package oauth2
|
|
|
|
import (
|
|
"io/ioutil"
|
|
"net/http"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
"golang.org/x/oauth2"
|
|
"gopkg.in/authboss.v0"
|
|
)
|
|
|
|
func TestGoogle(t *testing.T) {
|
|
saveClientGet := clientGet
|
|
defer func() {
|
|
clientGet = saveClientGet
|
|
}()
|
|
|
|
clientGet = func(_ *http.Client, url string) (*http.Response, error) {
|
|
return &http.Response{
|
|
Body: ioutil.NopCloser(strings.NewReader(`{"id":"id", "email":"email"}`)),
|
|
}, nil
|
|
}
|
|
|
|
cfg := *testProviders["google"].OAuth2Config
|
|
tok := &oauth2.Token{
|
|
AccessToken: "token",
|
|
TokenType: "Bearer",
|
|
RefreshToken: "refresh",
|
|
Expiry: time.Now().Add(60 * time.Minute),
|
|
}
|
|
|
|
user, err := Google(cfg, tok)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if uid, ok := user[authboss.StoreOAuth2UID]; !ok || uid != "id" {
|
|
t.Error("UID wrong:", uid)
|
|
}
|
|
if email, ok := user[authboss.StoreEmail]; !ok || email != "email" {
|
|
t.Error("Email wrong:", email)
|
|
}
|
|
}
|