diff --git a/auth.go b/auth.go index 526c16e..5beada8 100644 --- a/auth.go +++ b/auth.go @@ -20,7 +20,7 @@ func (c *Client) GetAuthorizationCodeURL(redirectURI string, scopes []string) (s scopes = []string{"profile", "email"} } - return c.APIBase + "/webapps/auth/protocol/openidconnect/v1/authorize?client_id=" + + return strings.Replace(c.APIBase, "api.", "", -1) + "/webapps/auth/protocol/openidconnect/v1/authorize?client_id=" + url.QueryEscape(c.ClientID) + "&response_type=code&scope=" + strings.Join(scopes, "+") + "&redirect_uri=" + url.QueryEscape(redirectURI), nil } diff --git a/auth_test.go b/auth_test.go index 031c40f..4cadc5c 100644 --- a/auth_test.go +++ b/auth_test.go @@ -13,13 +13,13 @@ func TestGetAuthorizationCodeURL(t *testing.T) { } uri, err := c.GetAuthorizationCodeURL("test", []string{}) - if uri != "https://api.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?client_id=clid&response_type=code&scope=profile+email&redirect_uri=test" { - t.Errorf("GetAuthorizationCodeURL returns incorrect value for redirectURI=test") + if uri != "https://sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?client_id=clid&response_type=code&scope=profile+email&redirect_uri=test" { + t.Errorf("GetAuthorizationCodeURL returns incorrect value for redirectURI=test " + uri) } uri, err = c.GetAuthorizationCodeURL("test", []string{"address"}) - if uri != "https://api.sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?client_id=clid&response_type=code&scope=address&redirect_uri=test" { - t.Errorf("GetAuthorizationCodeURL returns incorrect value for redirectURI=test and scope=address") + if uri != "https://sandbox.paypal.com/webapps/auth/protocol/openidconnect/v1/authorize?client_id=clid&response_type=code&scope=address&redirect_uri=test" { + t.Errorf("GetAuthorizationCodeURL returns incorrect value for redirectURI=test and scope=address " + uri) } }