diff --git a/README.md b/README.md index 2589255..15d32bc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Authentication framework for Go applications. ## Features * OAuth2 today - * Supports other protocols too + * Supports other protocols too * [Multiple providers](https://github.com/stretchr/gomniauth/tree/master/providers) * Comes with Google and GitHub baked in * Easily extensible @@ -37,8 +37,8 @@ First and only once for your application, you need to setup the security key and You are free to use the [signature package's RandomKey function](http://godoc.org/github.com/stretchr/signature#RandomKey) to generate a unique code every time your application starts. - gomniauth.SetSecurityKey(signature.RandomKey(64)) - + gomniauth.SetSecurityKey(signature.RandomKey(64)) + A provider represents an authentication service that will be available to your users. Usually, you'll have to add some configuration of your own, such as your application `key` and `secret` (provided by the auth service), and the `callback` into your app where users will be sent following successful (or not) authentication. gomniauth.WithProviders( @@ -82,7 +82,7 @@ You should then redirect the user to the `authUrl`. The `state` parameter is a `State` object that contains information that will be hashed and passed (via the third party) through to your callback (see below). Usually, this object contains the URL to redirect to once authentication has completed, but you can store whatever you like in here. -The `options` parameter is an `objects.Map` containing additional query-string parameters that will be sent to the authentication service. For example, in OAuth2 implementations, you can specify a `scope` parameter to get additional access to other services you might need. +The `options` parameter is an `objx.Map` containing additional query-string parameters that will be sent to the authentication service. For example, in OAuth2 implementations, you can specify a `scope` parameter to get additional access to other services you might need. ### Handling the callback @@ -107,8 +107,8 @@ The provider will then do the work in the background to complete the authenticat If you then want some information about the user who just authenticated, you can call the `GetUser` method on the provider (passing in the `creds` from the `CompleteAuth` method.) -The [User](https://github.com/stretchr/gomniauth/blob/master/common/user.go) you get back will give you access to the common user data you will need (like name, email, avatar URL etc) and also an `objects.Map` of `Data()` that contains everything else. +The [User](https://github.com/stretchr/gomniauth/blob/master/common/user.go) you get back will give you access to the common user data you will need (like name, email, avatar URL etc) and also an `objx.Map` of `Data()` that contains everything else. ### Caching in -Once you had the credentials for a user for a given provider, you should cache them in your own datastore. This will mean that if the cookie hasn't expired, or if the client has stored the auth token, they can continue to use the service without having to log in again. \ No newline at end of file +Once you had the credentials for a user for a given provider, you should cache them in your own datastore. This will mean that if the cookie hasn't expired, or if the client has stored the auth token, they can continue to use the service without having to log in again. diff --git a/common/config.go b/common/config.go index f6dcb5b..6de5854 100644 --- a/common/config.go +++ b/common/config.go @@ -1,11 +1,11 @@ package common import ( - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" ) // Config represent data that describes information needed // to make authenticated requests. type Config struct { - objects.Map + objx.Map } diff --git a/common/credentials.go b/common/credentials.go index df80768..ee293f6 100644 --- a/common/credentials.go +++ b/common/credentials.go @@ -2,7 +2,7 @@ package common import ( "fmt" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "strconv" ) @@ -13,7 +13,7 @@ const ( // Credentials represent data that describes information needed // to make authenticated requests. type Credentials struct { - objects.Map + objx.Map } var EmptyCredentials *Credentials = nil @@ -22,7 +22,7 @@ var EmptyCredentials *Credentials = nil func (c *Credentials) PublicData(options map[string]interface{}) (publicData interface{}, err error) { // ensure the ID is a string - idValue := c.Map.Get(CredentialsKeyID) + idValue := c.Map.Get(CredentialsKeyID).Data() var idStringValue string switch idValue.(type) { case float64: diff --git a/common/credentials_test.go b/common/credentials_test.go index 1d7bcc9..76195a0 100644 --- a/common/credentials_test.go +++ b/common/credentials_test.go @@ -3,20 +3,20 @@ package common import ( "github.com/stretchr/codecs" "github.com/stretchr/core/stretchr/constants" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "testing" ) func TestCredentials_PublicData(t *testing.T) { - creds := &Credentials{objects.M(constants.ParamAuthCode, "ABC123", CredentialsKeyID, 123)} + creds := &Credentials{objx.MSI(constants.ParamAuthCode, "ABC123", CredentialsKeyID, 123)} publicData, _ := codecs.PublicData(creds, nil) if assert.NotNil(t, publicData) { - assert.Equal(t, "ABC123", publicData.(objects.Map)[constants.ParamAuthCode]) - assert.Equal(t, "123", publicData.(objects.Map)[CredentialsKeyID], "CredentialsKeyID ("+CredentialsKeyID+") must be turned into a string.") + assert.Equal(t, "ABC123", publicData.(objx.Map)[constants.ParamAuthCode]) + assert.Equal(t, "123", publicData.(objx.Map)[CredentialsKeyID], "CredentialsKeyID ("+CredentialsKeyID+") must be turned into a string.") } } diff --git a/common/provider.go b/common/provider.go index e4cc6ba..9ef514e 100644 --- a/common/provider.go +++ b/common/provider.go @@ -1,7 +1,7 @@ package common import ( - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "net/http" ) @@ -18,12 +18,12 @@ type Provider interface { // callback endpoint. // The options argument takes any options used to configure the auth request // sent to the provider. - GetBeginAuthURL(state *State, options objects.Map) (string, error) + GetBeginAuthURL(state *State, options objx.Map) (string, error) // CompleteAuth takes a map of arguments that are used to // complete the authorisation process, completes it, and returns // the appropriate Credentials. - CompleteAuth(data objects.Map) (*Credentials, error) + CompleteAuth(data objx.Map) (*Credentials, error) // GetUser uses the specified Credentials to access the users profile // from the remote provider, and builds the appropriate User object. @@ -31,7 +31,7 @@ type Provider interface { // Get makes an authenticated request and returns the data in the // response as a data map. - Get(creds *Credentials, endpoint string) (objects.Map, error) + Get(creds *Credentials, endpoint string) (objx.Map, error) // GetClient gets an http.Client authenticated with the specified // Credentials. diff --git a/common/state.go b/common/state.go index 6a5a34a..e1969a0 100644 --- a/common/state.go +++ b/common/state.go @@ -1,17 +1,17 @@ package common import ( - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" ) // State represents a map of state arguments that can be used to // persist values across the authentication process. type State struct { - objects.Map + objx.Map } // NewState creates a new object that can be used to persist // state across authentication requests. func NewState(keyAndValuePairs ...interface{}) *State { - return &State{objects.M(keyAndValuePairs...)} + return &State{objx.MSI(keyAndValuePairs...)} } diff --git a/common/user.go b/common/user.go index 57a8eb3..2236bae 100644 --- a/common/user.go +++ b/common/user.go @@ -1,7 +1,7 @@ package common import ( - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" ) const ( @@ -33,5 +33,5 @@ type User interface { AuthCode() string // Data gets the underlying data that makes up this User. - Data() objects.Map + Data() objx.Map } diff --git a/example/goweb/main.go b/example/goweb/main.go index 2649d1a..6dbc33e 100644 --- a/example/goweb/main.go +++ b/example/goweb/main.go @@ -61,7 +61,7 @@ func main() { // if you want to request additional scopes from the provider, // pass them as login?scope=scope1,scope2 - //options := objects.M("scope", ctx.QueryValue("scope")) + //options := objx.MSI("scope", ctx.QueryValue("scope")) authUrl, err := provider.GetBeginAuthURL(state, nil) diff --git a/oauth2/complete_auth.go b/oauth2/complete_auth.go index ad3e8b3..0030d20 100644 --- a/oauth2/complete_auth.go +++ b/oauth2/complete_auth.go @@ -4,7 +4,7 @@ import ( "encoding/json" "fmt" "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "io/ioutil" "mime" "net/http" @@ -17,10 +17,10 @@ import ( // // The data must contain an OAuth2KeyCode obtained from the auth // server. -func CompleteAuth(tripperFactory common.TripperFactory, data objects.Map, config *common.Config, provider common.Provider) (*common.Credentials, error) { +func CompleteAuth(tripperFactory common.TripperFactory, data objx.Map, config *common.Config, provider common.Provider) (*common.Credentials, error) { // get the code - codeList := data.Get(OAuth2KeyCode) + codeList := data.Get(OAuth2KeyCode).Data() code, ok := codeList.(string) if !ok { @@ -39,15 +39,15 @@ func CompleteAuth(tripperFactory common.TripperFactory, data objects.Map, config return nil, clientErr } - params := objects.M(OAuth2KeyGrantType, OAuth2GrantTypeAuthorizationCode, - OAuth2KeyRedirectUrl, config.GetStringOrEmpty(OAuth2KeyRedirectUrl), - OAuth2KeyScope, config.GetStringOrEmpty(OAuth2KeyScope), + params := objx.MSI(OAuth2KeyGrantType, OAuth2GrantTypeAuthorizationCode, + OAuth2KeyRedirectUrl, config.Get(OAuth2KeyRedirectUrl).Str(), + OAuth2KeyScope, config.Get(OAuth2KeyScope).Str(), OAuth2KeyCode, code, - OAuth2KeyClientID, config.GetStringOrEmpty(OAuth2KeyClientID), - OAuth2KeySecret, config.GetStringOrEmpty(OAuth2KeySecret)) + OAuth2KeyClientID, config.Get(OAuth2KeyClientID).Str(), + OAuth2KeySecret, config.Get(OAuth2KeySecret).Str()) // post the form - response, requestErr := client.PostForm(config.GetString(OAuth2KeyTokenURL), params.URLValues()) + response, requestErr := client.PostForm(config.Get(OAuth2KeyTokenURL).Str(), params.URLValues()) if requestErr != nil { return nil, requestErr @@ -72,7 +72,7 @@ func CompleteAuth(tripperFactory common.TripperFactory, data objects.Map, config } // prepare the credentials object - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} body, err := ioutil.ReadAll(response.Body) if err != nil { @@ -82,25 +82,25 @@ func CompleteAuth(tripperFactory common.TripperFactory, data objects.Map, config switch content { case "application/x-www-form-urlencoded", "text/plain": - vals, err := objects.NewMapFromURLQuery(string(body)) + vals, err := objx.FromURLQuery(string(body)) if err != nil { return nil, err } // did an error occur? - if len(vals.GetStringOrEmpty("error")) > 0 { - return nil, &common.AuthServerError{ErrorMessage: vals.GetStringOrEmpty("error")} + if len(vals.Get("error").Str()) > 0 { + return nil, &common.AuthServerError{ErrorMessage: vals.Get("error").Str()} } - expiresIn, _ := time.ParseDuration(vals.GetStringOrEmpty(OAuth2KeyExpiresIn) + "s") + expiresIn, _ := time.ParseDuration(vals.Get(OAuth2KeyExpiresIn).Str() + "s") - creds.Set(OAuth2KeyAccessToken, vals.GetStringOrEmpty(OAuth2KeyAccessToken)) - creds.Set(OAuth2KeyRefreshToken, vals.GetStringOrEmpty(OAuth2KeyRefreshToken)) + creds.Set(OAuth2KeyAccessToken, vals.Get(OAuth2KeyAccessToken).Str()) + creds.Set(OAuth2KeyRefreshToken, vals.Get(OAuth2KeyRefreshToken).Str()) creds.Set(OAuth2KeyExpiresIn, expiresIn) default: // use JSON - var data objects.Map + var data objx.Map jsonErr := json.Unmarshal(body, &data) @@ -109,7 +109,7 @@ func CompleteAuth(tripperFactory common.TripperFactory, data objects.Map, config } // handle the time - timeDuration := data.Get(OAuth2KeyExpiresIn).(float64) + timeDuration := data.Get(OAuth2KeyExpiresIn).Float64() data.Set(OAuth2KeyExpiresIn, time.Duration(timeDuration)*time.Second) // merge this data into the creds diff --git a/oauth2/complete_auth_test.go b/oauth2/complete_auth_test.go index d6ef84d..82fafb7 100644 --- a/oauth2/complete_auth_test.go +++ b/oauth2/complete_auth_test.go @@ -3,7 +3,7 @@ package oauth2 import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "io/ioutil" @@ -16,7 +16,7 @@ import ( func TestOAuth2Provider_CompleteAuth_URLEncodedResponse(t *testing.T) { config := &common.Config{ - Map: objects.M( + Map: objx.MSI( OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl, OAuth2KeyScope, OAuth2KeyScope, OAuth2KeyClientID, OAuth2KeyClientID, @@ -39,15 +39,15 @@ func TestOAuth2Provider_CompleteAuth_URLEncodedResponse(t *testing.T) { testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil) testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil) - data := objects.M(OAuth2KeyCode, []string{"123"}) + data := objx.MSI(OAuth2KeyCode, []string{"123"}) creds, err := CompleteAuth(testTripperFactory, data, config, testProvider) if assert.NoError(t, err) { if assert.NotNil(t, creds, "Creds should be returned") { - assert.Equal(t, creds.GetStringOrEmpty(OAuth2KeyAccessToken), "ACCESSTOKEN") - assert.Equal(t, creds.GetStringOrEmpty(OAuth2KeyRefreshToken), "REFRESHTOKEN") - assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).(time.Duration), 20000000000) + assert.Equal(t, creds.Get(OAuth2KeyAccessToken).Str(), "ACCESSTOKEN") + assert.Equal(t, creds.Get(OAuth2KeyRefreshToken).Str(), "REFRESHTOKEN") + assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).Data().(time.Duration), 20000000000) } } @@ -59,7 +59,7 @@ func TestOAuth2Provider_CompleteAuth_URLEncodedResponse(t *testing.T) { func TestOAuth2Provider_Non200Response(t *testing.T) { config := &common.Config{ - Map: objects.M( + Map: objx.MSI( OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl, OAuth2KeyScope, OAuth2KeyScope, OAuth2KeyClientID, OAuth2KeyClientID, @@ -80,7 +80,7 @@ func TestOAuth2Provider_Non200Response(t *testing.T) { testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil) testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil) - data := objects.M(OAuth2KeyCode, []string{"123"}) + data := objx.MSI(OAuth2KeyCode, []string{"123"}) _, err := CompleteAuth(testTripperFactory, data, config, testProvider) if assert.Error(t, err) { @@ -94,7 +94,7 @@ func TestOAuth2Provider_Non200Response(t *testing.T) { func TestOAuth2Provider_CompleteAuth_JSON(t *testing.T) { config := &common.Config{ - Map: objects.M( + Map: objx.MSI( OAuth2KeyRedirectUrl, OAuth2KeyRedirectUrl, OAuth2KeyScope, OAuth2KeyScope, OAuth2KeyClientID, OAuth2KeyClientID, @@ -117,15 +117,15 @@ func TestOAuth2Provider_CompleteAuth_JSON(t *testing.T) { testTripperFactory.On("NewTripper", common.EmptyCredentials, mock.Anything).Return(testTripper, nil) testTripper.On("RoundTrip", mock.Anything).Return(testResponse, nil) - data := objects.M(OAuth2KeyCode, []string{"123"}) + data := objx.MSI(OAuth2KeyCode, []string{"123"}) creds, err := CompleteAuth(testTripperFactory, data, config, testProvider) if assert.NoError(t, err) { if assert.NotNil(t, creds, "Creds should be returned") { - assert.Equal(t, creds.GetStringOrEmpty(OAuth2KeyAccessToken), "ACCESSTOKEN") - assert.Equal(t, creds.GetStringOrEmpty(OAuth2KeyRefreshToken), "REFRESHTOKEN") - assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).(time.Duration), 20000000000) + assert.Equal(t, creds.Get(OAuth2KeyAccessToken).Str(), "ACCESSTOKEN") + assert.Equal(t, creds.Get(OAuth2KeyRefreshToken).Str(), "REFRESHTOKEN") + assert.Equal(t, creds.Get(OAuth2KeyExpiresIn).Data().(time.Duration), 20000000000) } } diff --git a/oauth2/get.go b/oauth2/get.go index 8f3905f..9afc697 100644 --- a/oauth2/get.go +++ b/oauth2/get.go @@ -3,15 +3,15 @@ package oauth2 import ( "github.com/stretchr/codecs/services" "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "io/ioutil" ) // Get executes an authenticated HTTP GET against the given provider and returns an -// objects.Map of the response. +// objx.Map of the response. // // The response type is automatically detected and used to unmarshal the response. -func Get(provider common.Provider, creds *common.Credentials, endpoint string) (objects.Map, error) { +func Get(provider common.Provider, creds *common.Credentials, endpoint string) (objx.Map, error) { client, clientErr := provider.GetClient(creds) @@ -40,7 +40,7 @@ func Get(provider common.Provider, creds *common.Credentials, endpoint string) ( return nil, getCodecErr } - var data objects.Map + var data objx.Map unmarshalErr := codec.Unmarshal(body, &data) if unmarshalErr != nil { diff --git a/oauth2/header.go b/oauth2/header.go index 89742de..22208e4 100644 --- a/oauth2/header.go +++ b/oauth2/header.go @@ -6,5 +6,5 @@ import ( // AuthorizationHeader returns the key, value pair to insert into an authorized request. func AuthorizationHeader(creds *common.Credentials) (key, value string) { - return "Authorization", "Bearer " + creds.GetStringOrDefault(OAuth2KeyAccessToken, "Invalid") + return "Authorization", "Bearer " + creds.Get(OAuth2KeyAccessToken).Str("Invalid") } diff --git a/oauth2/header_test.go b/oauth2/header_test.go index 96357ec..c798bce 100644 --- a/oauth2/header_test.go +++ b/oauth2/header_test.go @@ -2,14 +2,14 @@ package oauth2 import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "testing" ) func TestAuthorizationHeader(t *testing.T) { - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} accessTokenVal := "ACCESSTOKEN" creds.Set(OAuth2KeyAccessToken, accessTokenVal) k, v := AuthorizationHeader(creds) diff --git a/oauth2/oauth2_tripper_test.go b/oauth2/oauth2_tripper_test.go index 88a32a1..d57346f 100644 --- a/oauth2/oauth2_tripper_test.go +++ b/oauth2/oauth2_tripper_test.go @@ -3,7 +3,7 @@ package oauth2 import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" testifyhttp "github.com/stretchr/testify/http" "github.com/stretchr/testify/mock" @@ -14,7 +14,7 @@ import ( func TestNewOAuth2Tripper(t *testing.T) { testProvider := new(test.TestProvider) - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} var tripper common.Tripper = NewOAuth2Tripper(creds, testProvider) if assert.NotNil(t, tripper) { @@ -29,7 +29,7 @@ func TestRoundTrip(t *testing.T) { underlyingTripper := new(testifyhttp.TestRoundTripper) testProvider := new(test.TestProvider) - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} creds.Set(OAuth2KeyAccessToken, "This is a real access token :)") tripper := new(OAuth2Tripper) diff --git a/oauth2/url.go b/oauth2/url.go index f595a69..f3fe16c 100644 --- a/oauth2/url.go +++ b/oauth2/url.go @@ -2,7 +2,7 @@ package oauth2 import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" ) // GetBeginAuthURLWithBase returns the OAuth2 authorization URL from the given arguments. @@ -15,13 +15,13 @@ func GetBeginAuthURLWithBase(base string, state *common.State, config *common.Co } // copy the config - params := objects.M( - OAuth2KeyClientID, config.GetStringOrEmpty(OAuth2KeyClientID), - OAuth2KeyRedirectUrl, config.GetStringOrEmpty(OAuth2KeyRedirectUrl), - OAuth2KeyScope, config.GetStringOrEmpty(OAuth2KeyScope), - OAuth2KeyAccessType, config.GetStringOrEmpty(OAuth2KeyAccessType), - OAuth2KeyApprovalPrompt, config.GetStringOrEmpty(OAuth2KeyApprovalPrompt), - OAuth2KeyResponseType, config.GetStringOrEmpty(OAuth2KeyResponseType)) + params := objx.MSI( + OAuth2KeyClientID, config.Get(OAuth2KeyClientID).Str(), + OAuth2KeyRedirectUrl, config.Get(OAuth2KeyRedirectUrl).Str(), + OAuth2KeyScope, config.Get(OAuth2KeyScope).Str(), + OAuth2KeyAccessType, config.Get(OAuth2KeyAccessType).Str(), + OAuth2KeyApprovalPrompt, config.Get(OAuth2KeyApprovalPrompt).Str(), + OAuth2KeyResponseType, config.Get(OAuth2KeyResponseType).Str()) // set the state stateValue, stateErr := state.SignedBase64(common.GetSecurityKey()) diff --git a/oauth2/url_test.go b/oauth2/url_test.go index 3f2fbcf..f3f7054 100644 --- a/oauth2/url_test.go +++ b/oauth2/url_test.go @@ -2,7 +2,7 @@ package oauth2 import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "testing" ) @@ -13,7 +13,7 @@ func TestOAuth2HandlerBeginAuthURLWithBase(t *testing.T) { base := "https://base.url/auth" - config := &common.Config{Map: objects.M()} + config := &common.Config{Map: objx.MSI()} config. Set("client_id", "client_id"). Set("redirect_uri", "redirect_uri"). @@ -21,7 +21,7 @@ func TestOAuth2HandlerBeginAuthURLWithBase(t *testing.T) { Set("access_type", "access_type"). Set("approval_prompt", "approval_prompt") - state := &common.State{Map: objects.M("after", "http://www.stretchr.com/")} + state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")} base64State, _ := state.Base64() url, err := GetBeginAuthURLWithBase(base, state, config) @@ -43,7 +43,7 @@ func TestOAuth2HandlerBeginAuthURLWithBaseMultipleScope(t *testing.T) { base := "https://base.url/auth" - config := &common.Config{Map: objects.M()} + config := &common.Config{Map: objx.MSI()} config. Set("client_id", "client_id"). Set("redirect_uri", "redirect_uri"). @@ -51,7 +51,7 @@ func TestOAuth2HandlerBeginAuthURLWithBaseMultipleScope(t *testing.T) { Set("access_type", "access_type"). Set("approval_prompt", "approval_prompt") - state := &common.State{Map: objects.M("after", "http://www.stretchr.com/")} + state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")} base64State, _ := state.Base64() url, err := GetBeginAuthURLWithBase(base, state, config) diff --git a/providers/github/github.go b/providers/github/github.go index 531508c..946e4f8 100644 --- a/providers/github/github.go +++ b/providers/github/github.go @@ -3,7 +3,7 @@ package github import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "net/http" ) @@ -25,7 +25,7 @@ type GithubProvider struct { func New(clientId, clientSecret, redirectUrl string) *GithubProvider { p := new(GithubProvider) - p.config = &common.Config{Map: objects.M( + p.config = &common.Config{Map: objx.MSI( oauth2.OAuth2KeyAuthURL, githubAuthURL, oauth2.OAuth2KeyTokenURL, githubTokenURL, oauth2.OAuth2KeyClientID, clientId, @@ -61,17 +61,17 @@ func (provider *GithubProvider) Name() string { // The options argument takes any options used to configure the auth request // sent to the provider. In the case of OAuth2, the options map can contain: // 1. A "scope" key providing the desired scope(s). It will be merged with the default scope. -func (provider *GithubProvider) GetBeginAuthURL(state *common.State, options objects.Map) (string, error) { +func (provider *GithubProvider) GetBeginAuthURL(state *common.State, options objx.Map) (string, error) { if options != nil { - scope := oauth2.MergeScopes(options.GetStringOrEmpty(oauth2.OAuth2KeyScope), githubDefaultScope) + scope := oauth2.MergeScopes(options.Get(oauth2.OAuth2KeyScope).Str(), githubDefaultScope) provider.config.Set(oauth2.OAuth2KeyScope, scope) } - return oauth2.GetBeginAuthURLWithBase(provider.config.GetString(oauth2.OAuth2KeyAuthURL), state, provider.config) + return oauth2.GetBeginAuthURLWithBase(provider.config.Get(oauth2.OAuth2KeyAuthURL).Str(), state, provider.config) } // Get makes an authenticated request and returns the data in the // response as a data map. -func (provider *GithubProvider) Get(creds *common.Credentials, endpoint string) (objects.Map, error) { +func (provider *GithubProvider) Get(creds *common.Credentials, endpoint string) (objx.Map, error) { return oauth2.Get(provider, creds, endpoint) } @@ -94,7 +94,7 @@ func (provider *GithubProvider) GetUser(creds *common.Credentials) (common.User, // CompleteAuth takes a map of arguments that are used to // complete the authorisation process, completes it, and returns // the appropriate Credentials. -func (provider *GithubProvider) CompleteAuth(data objects.Map) (*common.Credentials, error) { +func (provider *GithubProvider) CompleteAuth(data objx.Map) (*common.Credentials, error) { return oauth2.CompleteAuth(provider.TripperFactory(), data, provider.config, provider) } diff --git a/providers/github/github_test.go b/providers/github/github_test.go index 9577917..e80b4f3 100644 --- a/providers/github/github_test.go +++ b/providers/github/github_test.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "io/ioutil" @@ -25,7 +25,7 @@ func TestGitHubImplementrsProvider(t *testing.T) { func TestGetUser(t *testing.T) { g := New("clientID", "secret", "http://myapp.com/") - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} testTripperFactory := new(test.TestTripperFactory) testTripper := new(test.TestTripper) @@ -52,7 +52,7 @@ func TestGetUser(t *testing.T) { githubCreds := user.ProviderCredentials()[githubName] if assert.NotNil(t, githubCreds) { - assert.Equal(t, "uniqueid", githubCreds.GetStringOrEmpty(common.CredentialsKeyID)) + assert.Equal(t, "uniqueid", githubCreds.Get(common.CredentialsKeyID).Str()) } } @@ -68,13 +68,13 @@ func TestNewGithub(t *testing.T) { // check config if assert.NotNil(t, g.config) { - assert.Equal(t, "clientID", g.config.Get(oauth2.OAuth2KeyClientID)) - assert.Equal(t, "secret", g.config.Get(oauth2.OAuth2KeySecret)) - assert.Equal(t, "http://myapp.com/", g.config.Get(oauth2.OAuth2KeyRedirectUrl)) - assert.Equal(t, githubDefaultScope, g.config.Get(oauth2.OAuth2KeyScope)) + assert.Equal(t, "clientID", g.config.Get(oauth2.OAuth2KeyClientID).Data()) + assert.Equal(t, "secret", g.config.Get(oauth2.OAuth2KeySecret).Data()) + assert.Equal(t, "http://myapp.com/", g.config.Get(oauth2.OAuth2KeyRedirectUrl).Data()) + assert.Equal(t, githubDefaultScope, g.config.Get(oauth2.OAuth2KeyScope).Data()) - assert.Equal(t, githubAuthURL, g.config.Get(oauth2.OAuth2KeyAuthURL)) - assert.Equal(t, githubTokenURL, g.config.Get(oauth2.OAuth2KeyTokenURL)) + assert.Equal(t, githubAuthURL, g.config.Get(oauth2.OAuth2KeyAuthURL).Data()) + assert.Equal(t, githubTokenURL, g.config.Get(oauth2.OAuth2KeyTokenURL).Data()) } @@ -104,7 +104,7 @@ func TestGitHubGetBeginAuthURL(t *testing.T) { common.SetSecurityKey("ABC123") - state := &common.State{Map: objects.M("after", "http://www.stretchr.com/")} + state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")} g := New("clientID", "secret", "http://myapp.com/") @@ -118,11 +118,11 @@ func TestGitHubGetBeginAuthURL(t *testing.T) { assert.Contains(t, url, "approval_prompt="+oauth2.OAuth2ApprovalPromptAuto) } - state = &common.State{Map: objects.M("after", "http://www.stretchr.com/")} + state = &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")} g = New("clientID", "secret", "http://myapp.com/") - url, err = g.GetBeginAuthURL(state, objects.M(oauth2.OAuth2KeyScope, "avatar")) + url, err = g.GetBeginAuthURL(state, objx.MSI(oauth2.OAuth2KeyScope, "avatar")) if assert.NoError(t, err) { assert.Contains(t, url, "client_id=clientID") diff --git a/providers/github/user.go b/providers/github/user.go index 761e537..a1ddec3 100644 --- a/providers/github/user.go +++ b/providers/github/user.go @@ -2,7 +2,7 @@ package github import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "strconv" ) @@ -15,11 +15,11 @@ const ( ) type User struct { - data objects.Map + data objx.Map } // NewUser builds a new User object for Github. -func NewUser(data objects.Map, creds *common.Credentials, provider common.Provider) *User { +func NewUser(data objx.Map, creds *common.Credentials, provider common.Provider) *User { user := &User{data} creds.Set(common.CredentialsKeyID, data[githubKeyID]) @@ -33,35 +33,35 @@ func NewUser(data objects.Map, creds *common.Credentials, provider common.Provid // Email gets the users email address. func (u *User) Email() string { - return u.Data().GetStringOrEmpty(githubKeyEmail) + return u.Data().Get(githubKeyEmail).Str() } // Name gets the users full name. func (u *User) Name() string { - return u.Data().GetStringOrEmpty(githubKeyName) + return u.Data().Get(githubKeyName).Str() } // Nickname gets the users nickname or username. func (u *User) Nickname() string { - return u.Data().GetStringOrEmpty(githubKeyNickname) + return u.Data().Get(githubKeyNickname).Str() } // AvatarURL gets the URL of an image representing the user. func (u *User) AvatarURL() string { - return u.Data().GetStringOrEmpty(githubKeyAvatarUrl) + return u.Data().Get(githubKeyAvatarUrl).Str() } // ProviderCredentials gets a map of Credentials (by provider name). func (u *User) ProviderCredentials() map[string]*common.Credentials { - return u.Data().Get(common.UserKeyProviderCredentials).(map[string]*common.Credentials) + return u.Data().Get(common.UserKeyProviderCredentials).Data().(map[string]*common.Credentials) } // IDForProvider gets the ID value for the specified provider name for // this user from the ProviderCredentials data. func (u *User) IDForProvider(provider string) string { - id := u.ProviderCredentials()[provider].Get(common.CredentialsKeyID) + id := u.ProviderCredentials()[provider].Get(common.CredentialsKeyID).Data() switch id.(type) { case string: return id.(string) @@ -73,11 +73,11 @@ func (u *User) IDForProvider(provider string) string { // AuthCode gets this user's globally unique ID (generated by the host program) func (u *User) AuthCode() string { - return u.Data().GetStringOrEmpty(common.UserKeyAuthCode) + return u.Data().Get(common.UserKeyAuthCode).Str() } // GetValue gets any User field by name. -func (u *User) Data() objects.Map { +func (u *User) Data() objx.Map { return u.data } diff --git a/providers/github/user_test.go b/providers/github/user_test.go index e9802b7..b0529bc 100644 --- a/providers/github/user_test.go +++ b/providers/github/user_test.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "testing" @@ -23,13 +23,13 @@ func TestNewUser(t *testing.T) { testProvider := new(test.TestProvider) testProvider.On("Name").Return("providerName") - data := objects.M( + data := objx.MSI( githubKeyID, "123435467890", githubKeyName, "Mathew", githubKeyEmail, "my@email.com", githubKeyNickname, "Mat", githubKeyAvatarUrl, "http://myface.com/") - creds := &common.Credentials{Map: objects.M(oauth2.OAuth2KeyAccessToken, "ABC123")} + creds := &common.Credentials{Map: objx.MSI(oauth2.OAuth2KeyAccessToken, "ABC123")} user := NewUser(data, creds, testProvider) @@ -45,8 +45,8 @@ func TestNewUser(t *testing.T) { // check provider credentials creds := user.ProviderCredentials()[testProvider.Name()] if assert.NotNil(t, creds) { - assert.Equal(t, "ABC123", creds.GetStringOrEmpty(oauth2.OAuth2KeyAccessToken)) - assert.Equal(t, "123435467890", creds.GetStringOrEmpty(common.CredentialsKeyID)) + assert.Equal(t, "ABC123", creds.Get(oauth2.OAuth2KeyAccessToken).Str()) + assert.Equal(t, "123435467890", creds.Get(common.CredentialsKeyID).Str()) } } @@ -58,11 +58,11 @@ func TestNewUser(t *testing.T) { func TestIDForProvider(t *testing.T) { user := new(User) - user.data = objects.M( + user.data = objx.MSI( common.UserKeyProviderCredentials, map[string]*common.Credentials{ - "github": &common.Credentials{Map: objects.M(common.CredentialsKeyID, "githubid")}, - "google": &common.Credentials{Map: objects.M(common.CredentialsKeyID, "googleid")}}) + "github": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "githubid")}, + "google": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "googleid")}}) assert.Equal(t, "githubid", user.IDForProvider("github")) assert.Equal(t, "googleid", user.IDForProvider("google")) diff --git a/providers/google/google.go b/providers/google/google.go index 0dfe70e..77b037f 100644 --- a/providers/google/google.go +++ b/providers/google/google.go @@ -3,7 +3,7 @@ package google import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "net/http" ) @@ -23,7 +23,7 @@ type GoogleProvider struct { func New(clientId, clientSecret, redirectUrl string) *GoogleProvider { p := new(GoogleProvider) - p.config = &common.Config{Map: objects.M( + p.config = &common.Config{Map: objx.MSI( oauth2.OAuth2KeyAuthURL, googleAuthURL, oauth2.OAuth2KeyTokenURL, googleTokenURL, oauth2.OAuth2KeyClientID, clientId, @@ -59,18 +59,18 @@ func (provider *GoogleProvider) Name() string { // The options argument takes any options used to configure the auth request // sent to the provider. In the case of OAuth2, the options map can contain: // 1. A "scope" key providing the desired scope(s). It will be merged with the default scope. -func (provider *GoogleProvider) GetBeginAuthURL(state *common.State, options objects.Map) (string, error) { +func (provider *GoogleProvider) GetBeginAuthURL(state *common.State, options objx.Map) (string, error) { if options != nil { - scope := oauth2.MergeScopes(options.GetStringOrEmpty(oauth2.OAuth2KeyScope), googleDefaultScope) + scope := oauth2.MergeScopes(options.Get(oauth2.OAuth2KeyScope).Str(), googleDefaultScope) provider.config.Set(oauth2.OAuth2KeyScope, scope) } - return oauth2.GetBeginAuthURLWithBase(provider.config.GetString(oauth2.OAuth2KeyAuthURL), state, provider.config) + return oauth2.GetBeginAuthURLWithBase(provider.config.Get(oauth2.OAuth2KeyAuthURL).Str(), state, provider.config) } // Get makes an authenticated request and returns the data in the // response as a data map. -func (provider *GoogleProvider) Get(creds *common.Credentials, endpoint string) (objects.Map, error) { +func (provider *GoogleProvider) Get(creds *common.Credentials, endpoint string) (objx.Map, error) { return oauth2.Get(provider, creds, endpoint) } @@ -93,7 +93,7 @@ func (provider *GoogleProvider) GetUser(creds *common.Credentials) (common.User, // CompleteAuth takes a map of arguments that are used to // complete the authorisation process, completes it, and returns // the appropriate Credentials. -func (provider *GoogleProvider) CompleteAuth(data objects.Map) (*common.Credentials, error) { +func (provider *GoogleProvider) CompleteAuth(data objx.Map) (*common.Credentials, error) { return oauth2.CompleteAuth(provider.TripperFactory(), data, provider.config, provider) } diff --git a/providers/google/google_test.go b/providers/google/google_test.go index 55d4fff..8a96b60 100644 --- a/providers/google/google_test.go +++ b/providers/google/google_test.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "io/ioutil" @@ -25,7 +25,7 @@ func TestGitHubImplementrsProvider(t *testing.T) { func TestGetUser(t *testing.T) { g := New("clientID", "secret", "http://myapp.com/") - creds := &common.Credentials{Map: objects.M()} + creds := &common.Credentials{Map: objx.MSI()} testTripperFactory := new(test.TestTripperFactory) testTripper := new(test.TestTripper) @@ -51,7 +51,7 @@ func TestGetUser(t *testing.T) { googleCreds := user.ProviderCredentials()[googleName] if assert.NotNil(t, googleCreds) { - assert.Equal(t, "uniqueid", googleCreds.GetStringOrEmpty(common.CredentialsKeyID)) + assert.Equal(t, "uniqueid", googleCreds.Get(common.CredentialsKeyID).Str()) } } @@ -67,13 +67,13 @@ func TestNewGoogle(t *testing.T) { // check config if assert.NotNil(t, g.config) { - assert.Equal(t, "clientID", g.config.Get(oauth2.OAuth2KeyClientID)) - assert.Equal(t, "secret", g.config.Get(oauth2.OAuth2KeySecret)) - assert.Equal(t, "http://myapp.com/", g.config.Get(oauth2.OAuth2KeyRedirectUrl)) - assert.Equal(t, googleDefaultScope, g.config.Get(oauth2.OAuth2KeyScope)) + assert.Equal(t, "clientID", g.config.Get(oauth2.OAuth2KeyClientID).Data()) + assert.Equal(t, "secret", g.config.Get(oauth2.OAuth2KeySecret).Data()) + assert.Equal(t, "http://myapp.com/", g.config.Get(oauth2.OAuth2KeyRedirectUrl).Data()) + assert.Equal(t, googleDefaultScope, g.config.Get(oauth2.OAuth2KeyScope).Data()) - assert.Equal(t, googleAuthURL, g.config.Get(oauth2.OAuth2KeyAuthURL)) - assert.Equal(t, googleTokenURL, g.config.Get(oauth2.OAuth2KeyTokenURL)) + assert.Equal(t, googleAuthURL, g.config.Get(oauth2.OAuth2KeyAuthURL).Data()) + assert.Equal(t, googleTokenURL, g.config.Get(oauth2.OAuth2KeyTokenURL).Data()) } @@ -103,7 +103,7 @@ func TestGitHubGetBeginAuthURL(t *testing.T) { common.SetSecurityKey("ABC123") - state := &common.State{Map: objects.M("after", "http://www.stretchr.com/")} + state := &common.State{Map: objx.MSI("after", "http://www.stretchr.com/")} g := New("clientID", "secret", "http://myapp.com/") diff --git a/providers/google/user.go b/providers/google/user.go index f524e2c..c9e3594 100644 --- a/providers/google/user.go +++ b/providers/google/user.go @@ -2,7 +2,7 @@ package google import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "strconv" ) @@ -14,10 +14,10 @@ const ( ) type User struct { - data objects.Map + data objx.Map } -func NewUser(data objects.Map, creds *common.Credentials, provider common.Provider) *User { +func NewUser(data objx.Map, creds *common.Credentials, provider common.Provider) *User { user := &User{data} creds.Set(common.CredentialsKeyID, data[googleKeyID]) @@ -32,12 +32,12 @@ func NewUser(data objects.Map, creds *common.Credentials, provider common.Provid // Email gets the users email address. func (u *User) Email() string { - return u.Data().GetStringOrEmpty(googleKeyEmail) + return u.Data().Get(googleKeyEmail).Str() } // Name gets the users full name. func (u *User) Name() string { - return u.Data().GetStringOrEmpty(googleKeyName) + return u.Data().Get(googleKeyName).Str() } @@ -49,18 +49,18 @@ func (u *User) Nickname() string { // AvatarURL gets the URL of an image representing the user. func (u *User) AvatarURL() string { - return u.Data().GetStringOrEmpty(googleKeyAvatarUrl) + return u.Data().Get(googleKeyAvatarUrl).Str() } // ProviderCredentials gets a map of Credentials (by provider name). func (u *User) ProviderCredentials() map[string]*common.Credentials { - return u.Data().Get(common.UserKeyProviderCredentials).(map[string]*common.Credentials) + return u.Data().Get(common.UserKeyProviderCredentials).Data().(map[string]*common.Credentials) } // IDForProvider gets the ID value for the specified provider name for // this user from the ProviderCredentials data. func (u *User) IDForProvider(provider string) string { - id := u.ProviderCredentials()[provider].Get(common.CredentialsKeyID) + id := u.ProviderCredentials()[provider].Get(common.CredentialsKeyID).Data() switch id.(type) { case string: return id.(string) @@ -72,11 +72,11 @@ func (u *User) IDForProvider(provider string) string { // AuthCode gets this user's globally unique ID (generated by the host program) func (u *User) AuthCode() string { - return u.Data().GetStringOrEmpty(common.UserKeyAuthCode) + return u.Data().Get(common.UserKeyAuthCode).Str() } // GetValue gets any User field by name. -func (u *User) Data() objects.Map { +func (u *User) Data() objx.Map { return u.data } diff --git a/providers/google/user_test.go b/providers/google/user_test.go index ae461a3..30639c5 100644 --- a/providers/google/user_test.go +++ b/providers/google/user_test.go @@ -4,7 +4,7 @@ import ( "github.com/stretchr/gomniauth/common" "github.com/stretchr/gomniauth/oauth2" "github.com/stretchr/gomniauth/test" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/mock" "testing" @@ -23,12 +23,12 @@ func TestNewUser(t *testing.T) { testProvider := new(test.TestProvider) testProvider.On("Name").Return("providerName") - data := objects.M( + data := objx.MSI( googleKeyID, "123435467890", googleKeyName, "Mathew", googleKeyEmail, "my@email.com", googleKeyAvatarUrl, "http://myface.com/") - creds := &common.Credentials{Map: objects.M(oauth2.OAuth2KeyAccessToken, "ABC123")} + creds := &common.Credentials{Map: objx.MSI(oauth2.OAuth2KeyAccessToken, "ABC123")} user := NewUser(data, creds, testProvider) @@ -43,8 +43,8 @@ func TestNewUser(t *testing.T) { // check provider credentials creds := user.ProviderCredentials()[testProvider.Name()] if assert.NotNil(t, creds) { - assert.Equal(t, "ABC123", creds.GetStringOrEmpty(oauth2.OAuth2KeyAccessToken)) - assert.Equal(t, "123435467890", creds.GetStringOrEmpty(common.CredentialsKeyID)) + assert.Equal(t, "ABC123", creds.Get(oauth2.OAuth2KeyAccessToken).Str()) + assert.Equal(t, "123435467890", creds.Get(common.CredentialsKeyID).Str()) } } @@ -56,11 +56,11 @@ func TestNewUser(t *testing.T) { func TestIDForProvider(t *testing.T) { user := new(User) - user.data = objects.M( + user.data = objx.MSI( common.UserKeyProviderCredentials, map[string]*common.Credentials{ - "github": &common.Credentials{Map: objects.M(common.CredentialsKeyID, "githubid")}, - "google": &common.Credentials{Map: objects.M(common.CredentialsKeyID, "googleid")}}) + "github": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "githubid")}, + "google": &common.Credentials{Map: objx.MSI(common.CredentialsKeyID, "googleid")}}) assert.Equal(t, "githubid", user.IDForProvider("github")) assert.Equal(t, "googleid", user.IDForProvider("google")) diff --git a/shortcuts.go b/shortcuts.go index 3c25d2f..7eb9051 100644 --- a/shortcuts.go +++ b/shortcuts.go @@ -2,7 +2,7 @@ package gomniauth import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" ) // Provider gets a provider by name from the @@ -22,7 +22,7 @@ func NewState(keyAndValuePairs ...interface{}) *common.State { // into a usable State object. func StateFromParam(paramValue string) (*common.State, error) { - stateMap, err := objects.NewMapFromSignedBase64String(paramValue, GetSecurityKey()) + stateMap, err := objx.FromSignedBase64(paramValue, GetSecurityKey()) if err != nil { return nil, err diff --git a/shortcuts_test.go b/shortcuts_test.go index a425088..f2e11f0 100644 --- a/shortcuts_test.go +++ b/shortcuts_test.go @@ -12,8 +12,8 @@ func TestNewState(t *testing.T) { s := NewState("one", 1, "two", 2) if assert.NotNil(t, s) { - assert.Equal(t, 1, s.Get("one")) - assert.Equal(t, 2, s.Get("two")) + assert.Equal(t, 1, s.Get("one").Data()) + assert.Equal(t, 2, s.Get("two").Data()) } } @@ -25,8 +25,8 @@ func TestStateFromParam(t *testing.T) { s, err := StateFromParam(hash) if assert.NotNil(t, s) && assert.NoError(t, err) { - assert.Equal(t, "Mat", s.Get("name")) - assert.Equal(t, 30, s.Get("age")) + assert.Equal(t, "Mat", s.Get("name").Data()) + assert.Equal(t, 30, s.Get("age").Data()) } } diff --git a/test/test_provider.go b/test/test_provider.go index 3c5a167..f23f399 100644 --- a/test/test_provider.go +++ b/test/test_provider.go @@ -2,7 +2,7 @@ package test import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/mock" "net/http" ) @@ -18,7 +18,7 @@ func (p *TestProvider) Name() string { // GetBeginAuthURL gets the URL that the client must visit in order // to begin the authentication process. -func (p *TestProvider) GetBeginAuthURL(state *common.State, options objects.Map) (string, error) { +func (p *TestProvider) GetBeginAuthURL(state *common.State, options objx.Map) (string, error) { args := p.Called(state, options) return args.String(0), args.Error(1) } @@ -26,14 +26,14 @@ func (p *TestProvider) GetBeginAuthURL(state *common.State, options objects.Map) // CompleteAuth takes a map of arguments that are used to // complete the authorisation process, completes it, and returns // the appropriate common.Credentials. -func (p *TestProvider) CompleteAuth(data objects.Map) (*common.Credentials, error) { +func (p *TestProvider) CompleteAuth(data objx.Map) (*common.Credentials, error) { args := p.Called(data) return args.Get(0).(*common.Credentials), args.Error(1) } -func (p *TestProvider) Get(creds *common.Credentials, endpoint string) (objects.Map, error) { +func (p *TestProvider) Get(creds *common.Credentials, endpoint string) (objx.Map, error) { args := p.Called(creds, endpoint) - return args.Get(0).(objects.Map), args.Error(1) + return args.Get(0).(objx.Map), args.Error(1) } // GetUser uses the specified common.Credentials to access the users profile diff --git a/test/test_user.go b/test/test_user.go index 4b9b71b..06031ac 100644 --- a/test/test_user.go +++ b/test/test_user.go @@ -2,7 +2,7 @@ package test import ( "github.com/stretchr/gomniauth/common" - "github.com/stretchr/stew/objects" + "github.com/stretchr/objx" "github.com/stretchr/testify/mock" ) @@ -47,6 +47,6 @@ func (u *TestUser) AuthCode() string { } // Data gets the underlying data that makes up this User. -func (u *TestUser) Data() objects.Map { - return u.Called().Get(0).(objects.Map) +func (u *TestUser) Data() objx.Map { + return u.Called().Get(0).(objx.Map) }