Merge lp:~vds/usso/handle_order_of_parameters into lp:usso

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Vincenzo Di Somma
Approved revision: 25
Merged at revision: 25
Proposed branch: lp:~vds/usso/handle_order_of_parameters
Merge into: lp:usso
Diff against target: 506 lines (+191/-141)
6 files modified
example/usso_example.go (+7/-12)
oauth.go (+90/-71)
oauth_test.go (+41/-26)
url.go (+36/-19)
url_test.go (+2/-2)
usso.go (+15/-11)
To merge this branch: bzr merge lp:~vds/usso/handle_order_of_parameters
Reviewer Review Type Date Requested Status
Graham Binns (community) code Approve
Domas Monkus (community) Approve
Review via email: mp+145936@code.launchpad.net

Commit message

"Got rid of useless error, using a struct to handle the oauth_signature_method, separated ssodata from temporary request parameters, fixed tests and example accordingly.

Description of the change

"Got rid of useless error, using a struct to handle the oauth_signature_method, separated ssodata from temporary request parameters, fixed tests and example accordingly.

To post a comment you must log in.
Revision history for this message
Domas Monkus (tasdomas) wrote :

Looks ok.

review: Approve
Revision history for this message
Graham Binns (gmb) wrote :

Hi Vincenzo,

Thank you for this branch! There are a couple of things you need to add before you land this, but there's nothing that needs me to re-review it after you've made the changes, so feel free to make them and then mark the MP as approved.

[1]

149 +func (PLAINTEXT) Name() string { return "PLAINTEXT" }
150 +func (PLAINTEXT) Signature(

160 +func (HMACSHA1) Name() string { return "HMAC-SHA1" }
161 +func (HMACSHA1) Signature(

These all need some documentation comments.

[2]

275 +// Test the request signing with oauth_signature_method = PLAINTEXT
301 // Test the request signing with oauth_signature_method = SHA1

We should avoid the "Test the..." style when writing documentation for tests. Instead, we should write things like:

  // It is possible to sign a request with a PLAINTEXT oauth_signature_method.
  // It is possible to sign a request with a SHA1 oauth_signature_method.

Put another way, the documentation on a test should be something that can be declared true if the test passes, false otherwise.

review: Approve (code)
25. By Vincenzo Di Somma

Fixing/adding comments and cleaning up.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'example/usso_example.go'
--- example/usso_example.go 2013-01-25 16:39:11 +0000
+++ example/usso_example.go 2013-02-05 12:38:20 +0000
@@ -9,7 +9,7 @@
9 "net/http"9 "net/http"
10)10)
1111
12var email, password, tokenName, signature_method string12var email, password string
1313
14func inputParams() {14func inputParams() {
15 fmt.Println("This application will query the staging Ubuntu SSO Server" +15 fmt.Println("This application will query the staging Ubuntu SSO Server" +
@@ -19,9 +19,6 @@
19 fmt.Print("Enter password: ")19 fmt.Print("Enter password: ")
20 fmt.Scanf("%s", &password)20 fmt.Scanf("%s", &password)
21 fmt.Print("Enter token name: ")21 fmt.Print("Enter token name: ")
22 fmt.Scanf("%s", &tokenName)
23 fmt.Print("Enter signature method (PLAINTEXT or HMAC-SHA1): ")
24 fmt.Scanf("%s", &signature_method)
25}22}
2623
27func main() {24func main() {
@@ -32,7 +29,7 @@
32 server := usso.StagingUbuntuSSOServer29 server := usso.StagingUbuntuSSOServer
33 // One would use server := usso.ProductionUbuntuSSOServer 30 // One would use server := usso.ProductionUbuntuSSOServer
34 // to use the production Ubuntu SSO Server.31 // to use the production Ubuntu SSO Server.
35 ssodata, err := server.GetToken(email, password, tokenName)32 ssodata, err := server.GetToken(email, password, "usso")
36 if err != nil {33 if err != nil {
37 panic(err)34 panic(err)
38 }35 }
@@ -48,14 +45,12 @@
48 //fmt.Printf("Got accounts info: %s\n", accounts)45 //fmt.Printf("Got accounts info: %s\n", accounts)
4946
50 // But this shows how to sign a generic request.47 // But this shows how to sign a generic request.
51 ssodata.BaseURL = fmt.Sprintf(48 rp := usso.RequestParameters{BaseURL: fmt.Sprintf(
52 "https://login.staging.ubuntu.com/api/v2/accounts/%s",49 "https://login.staging.ubuntu.com/api/v2/accounts/%s",
53 ssodata.ConsumerKey)50 ssodata.ConsumerKey), HTTPMethod: "GET",
54 ssodata.HTTPMethod = "GET"51 SignatureMethod: usso.HMACSHA1{}}
55 ssodata.SignatureMethod = signature_method52 request, _ := http.NewRequest(rp.HTTPMethod, rp.BaseURL, nil)
56 request, _ := http.NewRequest(ssodata.HTTPMethod, ssodata.BaseURL, nil)53 usso.SignRequest(ssodata, &rp, request)
57 usso.SignRequest(ssodata, request)
58
59 if err != nil {54 if err != nil {
60 fmt.Printf("Error: %s\n", err)55 fmt.Printf("Error: %s\n", err)
61 }56 }
6257
=== modified file 'oauth.go'
--- oauth.go 2013-01-29 11:23:37 +0000
+++ oauth.go 2013-02-05 12:38:20 +0000
@@ -4,7 +4,6 @@
4 "crypto/hmac"4 "crypto/hmac"
5 "crypto/sha1"5 "crypto/sha1"
6 "encoding/base64"6 "encoding/base64"
7 "errors"
8 "fmt"7 "fmt"
9 "math/rand"8 "math/rand"
10 "net/http"9 "net/http"
@@ -30,72 +29,91 @@
3029
31// Contains the oauth data to perform a request.30// Contains the oauth data to perform a request.
32type SSOData struct {31type SSOData struct {
33 HTTPMethod string `json:"-"`32 ConsumerKey string `json:"consumer_key"`
34 BaseURL string `json:"-"`33 ConsumerSecret string `json:"consumer_secret"`
35 Params url.Values `json:"-"`34 TokenKey string `json:"token_key"`
36 Nonce string `json:"-"`35 TokenName string `json:"token_name"`
37 Timestamp string `json:"-"`36 TokenSecret string `json:"token_secret"`
38 SignatureMethod string `json:"-"`37}
39 ConsumerKey string `json:"consumer_key"`38
40 ConsumerSecret string `json:"consumer_secret"`39type RequestParameters struct {
41 TokenKey string `json:"token_key"`40 HTTPMethod string
42 TokenName string `json:"token_name"`41 BaseURL string
43 TokenSecret string `json:"token_secret"`42 Params url.Values
44}43 Nonce string
4544 Timestamp string
46// Depending on the signature method, create the signature from the 45 SignatureMethod SignatureMethod
47// consumer secret, the token secret and, if required, the URL.46}
48// Supported signature methods are PLAINTEXT and HMAC-SHA1.47
49func (oauth *SSOData) signature() (string, error) {48type SignatureMethod interface {
50 switch oauth.SignatureMethod {49 Name() string
51 case "PLAINTEXT":50 Signature(
52 return fmt.Sprintf(51 ssodata *SSOData, rp *RequestParameters) (string, error)
53 `%s%%26%s`,52}
54 oauth.ConsumerSecret,53
55 oauth.TokenSecret), nil54type PLAINTEXT struct{}
56 case "HMAC-SHA1":55
57 base_url, err := NormalizeURL(oauth.BaseURL)56// Return the name of the signature method, used to compose the
58 if err != nil {57// Authentication Header.
59 return "", err58func (PLAINTEXT) Name() string { return "PLAINTEXT" }
60 }59
61 params, err := NormalizeParameters(oauth.Params)60// Calculate the oaut_signature part of the Authentication Header.
62 if err != nil {61func (PLAINTEXT) Signature(
63 return "", err62 ssodata *SSOData, rp *RequestParameters) (string, error) {
64 }63 return fmt.Sprintf(
65 base_string := fmt.Sprintf(`%s&%s&%s%s%s%s%s%s%s`,64 `%s&%s`,
66 oauth.HTTPMethod,65 ssodata.ConsumerSecret,
67 url.QueryEscape(base_url),66 ssodata.TokenSecret), nil
68 url.QueryEscape(params),67}
69 url.QueryEscape("oauth_consumer_key="+oauth.ConsumerKey),68
70 url.QueryEscape("&oauth_nonce="+oauth.Nonce),69type HMACSHA1 struct{}
71 url.QueryEscape("&oauth_signature_method="+oauth.SignatureMethod),70
72 url.QueryEscape("&oauth_timestamp="+oauth.Timestamp),71// Return the name of the signature method, used to compose the
73 url.QueryEscape("&oauth_token="+oauth.TokenKey),72// Authentication Header.
74 url.QueryEscape("&oauth_version=1.0"))73func (HMACSHA1) Name() string { return "HMAC-SHA1" }
75 hashfun := hmac.New(sha1.New, []byte(74
76 oauth.ConsumerSecret+"&"+oauth.TokenSecret))75// Calculate the oaut_signature part of the Authentication Header.
77 hashfun.Write([]byte(base_string))76func (HMACSHA1) Signature(
78 rawsignature := hashfun.Sum(nil)77 ssodata *SSOData, rp *RequestParameters) (string, error) {
79 base64signature := make(78 baseUrl, err := NormalizeURL(rp.BaseURL)
80 []byte, base64.StdEncoding.EncodedLen(len(rawsignature)))79 if err != nil {
81 base64.StdEncoding.Encode(base64signature, rawsignature)80 return "", err
82 return string(base64signature), nil81 }
83 default:82 params, err := NormalizeParameters(rp.Params)
84 return "", errors.New(83 if err != nil {
85 "usso/oauth: Oauth Signature Method not supported.")84 return "", err
86 }85 }
87 return "", nil86 baseString := fmt.Sprintf(`%s&%s&%s%s%s%s%s%s%s`,
87 rp.HTTPMethod,
88 url.QueryEscape(baseUrl),
89 url.QueryEscape(params),
90 url.QueryEscape("oauth_consumer_key="+ssodata.ConsumerKey),
91 url.QueryEscape("&oauth_nonce="+rp.Nonce),
92 url.QueryEscape(
93 "&oauth_signature_method="+string(rp.SignatureMethod.Name())),
94 url.QueryEscape("&oauth_timestamp="+rp.Timestamp),
95 url.QueryEscape("&oauth_token="+ssodata.TokenKey),
96 url.QueryEscape("&oauth_version=1.0"))
97 hashfun := hmac.New(sha1.New, []byte(
98 ssodata.ConsumerSecret+"&"+ssodata.TokenSecret))
99 hashfun.Write([]byte(baseString))
100 rawsignature := hashfun.Sum(nil)
101 base64signature := make(
102 []byte, base64.StdEncoding.EncodedLen(len(rawsignature)))
103 base64.StdEncoding.Encode(base64signature, rawsignature)
104 return string(base64signature), nil
88}105}
89106
90// Sign the provided request.107// Sign the provided request.
91func (oauth *SSOData) GetAuthorizationHeader() (string, error) {108func (ssodata *SSOData) GetAuthorizationHeader(
92 if oauth.Nonce == "" {109 rp *RequestParameters) (string, error) {
93 oauth.Nonce = nonce()110 if rp.Nonce == "" {
94 }111 rp.Nonce = nonce()
95 if oauth.Timestamp == "" {112 }
96 oauth.Timestamp = timestamp()113 if rp.Timestamp == "" {
97 }114 rp.Timestamp = timestamp()
98 signature, err := oauth.signature()115 }
116 signature, err := rp.SignatureMethod.Signature(ssodata, rp)
99 if err != nil {117 if err != nil {
100 return "", err118 return "", err
101 }119 }
@@ -108,19 +126,20 @@
108 `oauth_timestamp="%s", `+126 `oauth_timestamp="%s", `+
109 `oauth_nonce="%s", `+127 `oauth_nonce="%s", `+
110 `oauth_version="1.0"`,128 `oauth_version="1.0"`,
111 url.QueryEscape(oauth.ConsumerKey),129 url.QueryEscape(ssodata.ConsumerKey),
112 url.QueryEscape(oauth.TokenKey),130 url.QueryEscape(ssodata.TokenKey),
113 oauth.SignatureMethod,131 rp.SignatureMethod.Name(),
114 signature,132 signature,
115 url.QueryEscape(oauth.Timestamp),133 url.QueryEscape(rp.Timestamp),
116 url.QueryEscape(oauth.Nonce))134 url.QueryEscape(rp.Nonce))
117135
118 return auth, nil136 return auth, nil
119}137}
120138
121// Sign the provided request.139// Sign the provided request.
122func (oauth *SSOData) SignRequest(req *http.Request) error {140func (ssodata *SSOData) SignRequest(
123 auth, error := oauth.GetAuthorizationHeader()141 rp *RequestParameters, req *http.Request) error {
142 auth, error := ssodata.GetAuthorizationHeader(rp)
124 req.Header.Add("Authorization", auth)143 req.Header.Add("Authorization", auth)
125 return error144 return error
126}145}
127146
=== modified file 'oauth_test.go'
--- oauth_test.go 2013-01-29 11:23:37 +0000
+++ oauth_test.go 2013-02-05 12:38:20 +0000
@@ -6,47 +6,62 @@
6 "net/url"6 "net/url"
7)7)
88
9func (suite *USSOTestSuite) TestSignRequestPlainText(c *C) {9type OAuthTestSuite struct {
10 ssodata SSOData
11 rp RequestParameters
12 request *http.Request
13}
14
15var _ = Suite(&OAuthTestSuite{})
16
17func (suite *OAuthTestSuite) SetUpTest(c *C) {
10 baseUrl := "https://localhost"18 baseUrl := "https://localhost"
11 ssodata := SSOData{BaseURL: baseUrl, ConsumerKey: consumerKey,19 suite.ssodata = SSOData{ConsumerKey: consumerKey,
12 ConsumerSecret: consumerSecret, TokenKey: tokenKey,20 ConsumerSecret: consumerSecret, TokenKey: tokenKey,
13 TokenName: tokenName, TokenSecret: tokenSecret}21 TokenName: tokenName, TokenSecret: tokenSecret}
14 request, _ := http.NewRequest("GET", baseUrl, nil)22 suite.rp = RequestParameters{BaseURL: baseUrl, HTTPMethod: "GET",
15 ssodata.HTTPMethod = "GET"23 Nonce: "10888885", Timestamp: "1358853126"}
16 ssodata.SignatureMethod = "PLAINTEXT"24 suite.request, _ = http.NewRequest("GET", baseUrl, nil)
17 err := ssodata.SignRequest(request)25}
18 c.Assert(err, IsNil)26
19 authHeader := request.Header["Authorization"][0]27// It is possible to sign a request with oauth_signature_method = PLAINTEXT
28func (suite *OAuthTestSuite) TestSignRequestPlainText(c *C) {
29 suite.rp.SignatureMethod = PLAINTEXT{}
30 err := suite.ssodata.SignRequest(&suite.rp, suite.request)
31 if err != nil {
32 c.Log(err)
33 c.FailNow()
34 }
35 authHeader := suite.request.Header["Authorization"][0]
20 c.Assert(authHeader, Matches, `^OAuth.*`)36 c.Assert(authHeader, Matches, `^OAuth.*`)
21 c.Assert(authHeader, Matches, `.*realm="API".*`)37 c.Assert(authHeader, Matches, `.*realm="API".*`)
22 c.Assert(authHeader, Matches,38 c.Assert(authHeader, Matches,
23 `.*oauth_consumer_key="`+url.QueryEscape(ssodata.ConsumerKey)+`".*`)39 `.*oauth_consumer_key="`+url.QueryEscape(
40 suite.ssodata.ConsumerKey)+`".*`)
24 c.Assert(authHeader, Matches,41 c.Assert(authHeader, Matches,
25 `.*oauth_token="`+url.QueryEscape(ssodata.TokenKey)+`".*`)42 `.*oauth_token="`+url.QueryEscape(suite.ssodata.TokenKey)+`".*`)
26 c.Assert(authHeader, Matches,43 c.Assert(authHeader, Matches,
27 `.*oauth_signature="`+url.QueryEscape(44 `.*oauth_signature="`+url.QueryEscape(
28 ssodata.ConsumerSecret+`&`+ssodata.TokenSecret)+`.*`)45 suite.ssodata.ConsumerSecret)+`&`+url.QueryEscape(
46 suite.ssodata.TokenSecret)+`.*`)
29}47}
3048
31// Test the request signing with oauth_signature_method = SHA149// It is possible to sign a request with oauth_signature_method = SHA1
32func (suite *USSOTestSuite) TestSignRequestSHA1(c *C) {50func (suite *OAuthTestSuite) TestSignRequestSHA1(c *C) {
33 baseUrl := "https://localhost"51 suite.rp.SignatureMethod = HMACSHA1{}
34 ssodata := SSOData{BaseURL: baseUrl, ConsumerKey: consumerKey,52 err := suite.ssodata.SignRequest(&suite.rp, suite.request)
35 ConsumerSecret: consumerSecret, TokenKey: tokenKey,53 if err != nil {
36 TokenName: tokenName, TokenSecret: tokenSecret,54 c.Log(err)
37 Nonce: "10888885", Timestamp: "1358853126"}55 c.FailNow()
38 request, _ := http.NewRequest("GET", baseUrl, nil)56 }
39 ssodata.HTTPMethod = "GET"57 authHeader := suite.request.Header["Authorization"][0]
40 ssodata.SignatureMethod = "HMAC-SHA1"
41 err := ssodata.SignRequest(request)
42 c.Assert(err, IsNil)
43 authHeader := request.Header["Authorization"][0]
44 c.Assert(authHeader, Matches, `^OAuth.*`)58 c.Assert(authHeader, Matches, `^OAuth.*`)
45 c.Assert(authHeader, Matches, `.*realm="API".*`)59 c.Assert(authHeader, Matches, `.*realm="API".*`)
46 c.Assert(authHeader, Matches,60 c.Assert(authHeader, Matches,
47 `.*oauth_consumer_key="`+url.QueryEscape(ssodata.ConsumerKey)+`".*`)61 `.*oauth_consumer_key="`+url.QueryEscape(
62 suite.ssodata.ConsumerKey)+`".*`)
48 c.Assert(authHeader, Matches,63 c.Assert(authHeader, Matches,
49 `.*oauth_token="`+url.QueryEscape(ssodata.TokenKey)+`".*`)64 `.*oauth_token="`+url.QueryEscape(suite.ssodata.TokenKey)+`".*`)
50 c.Assert(authHeader, Matches,65 c.Assert(authHeader, Matches,
51 `.*oauth_signature="`+"amJnYeek4G9ObTgTiE2y6cwTyPg="+`.*`)66 `.*oauth_signature="`+"amJnYeek4G9ObTgTiE2y6cwTyPg="+`.*`)
52}67}
5368
=== modified file 'url.go'
--- url.go 2013-01-29 11:23:37 +0000
+++ url.go 2013-02-05 12:38:20 +0000
@@ -3,43 +3,60 @@
3import (3import (
4 "fmt"4 "fmt"
5 "net/url"5 "net/url"
6 "sort"
6 "strings"7 "strings"
7)8)
89
9// Remove the standard ports from the URL.10// Remove the standard ports from the URL.
10func normalizeHost(scheme, host_spec string) string {11func normalizeHost(scheme, hostSpec string) string {
11 standard_ports := map[string]string{12 standardPorts := map[string]string{
12 "http": "80",13 "http": "80",
13 "https": "443",14 "https": "443",
14 }15 }
15 host_parts := strings.Split(host_spec, ":")16 hostParts := strings.Split(hostSpec, ":")
16 if len(host_parts) == 2 && host_parts[1] == standard_ports[scheme] {17 if len(hostParts) == 2 && hostParts[1] == standardPorts[scheme] {
17 // There's a port, but it's the default one. Leave it out.18 // There's a port, but it's the default one. Leave it out.
18 return host_parts[0]19 return hostParts[0]
19 }20 }
20 return host_spec21 return hostSpec
21}22}
2223
23// Normalize the URL according to OAuth specs.24// Normalize the URL according to OAuth specs.
24func NormalizeURL(input_url string) (string, error) {25func NormalizeURL(inputUrl string) (string, error) {
25 parsed_url, err := url.Parse(input_url)26 parsedUrl, err := url.Parse(inputUrl)
26 if err != nil {27 if err != nil {
27 return "", err28 return "", err
28 }29 }
2930
30 host := normalizeHost(parsed_url.Scheme, parsed_url.Host)31 host := normalizeHost(parsedUrl.Scheme, parsedUrl.Host)
31 normalized_url := fmt.Sprintf(32 normalizedUrl := fmt.Sprintf(
32 "%v://%v%v", parsed_url.Scheme, host, parsed_url.Path)33 "%v://%v%v", parsedUrl.Scheme, host, parsedUrl.Path)
33 return normalized_url, nil34 return normalizedUrl, nil
34}35}
3536
36// Normalize the parameters in the query string according to OAuth specs.37// Normalize the parameters in the query string according to OAuth specs.
38// url.Values.Encode encoded the GET parameters in a consistent order
39// we do the encoding ourselves.
37func NormalizeParameters(parameters url.Values) (string, error) {40func NormalizeParameters(parameters url.Values) (string, error) {
38 filtered_map := make(url.Values, len(parameters))41 filteredMap := make(url.Values, len(parameters))
39 for param, value := range parameters {42 keys := make([]string, len(parameters))
40 if param != "oauth_signature" {43 i := 0
41 filtered_map[param] = value44 for key, _ := range parameters {
42 }45 keys[i] = key
43 }46 i++
44 return filtered_map.Encode(), nil47 }
48 sort.Strings(keys)
49 for _, key := range keys {
50 if key != "oauth_signature" {
51 filteredMap[key] = parameters[key]
52 }
53 }
54 parts := make([]string, 0, len(filteredMap))
55 for _, key := range keys {
56 prefix := url.QueryEscape(key) + "="
57 for _, v := range filteredMap[key] {
58 parts = append(parts, prefix+url.QueryEscape(v))
59 }
60 }
61 return strings.Join(parts, "&"), nil
45}62}
4663
=== modified file 'url_test.go'
--- url_test.go 2013-01-29 14:27:25 +0000
+++ url_test.go 2013-02-05 12:38:20 +0000
@@ -60,7 +60,7 @@
60 output, err := NormalizeParameters(60 output, err := NormalizeParameters(
61 url.Values{"a": []string{"1"}, "b": []string{"2"}})61 url.Values{"a": []string{"1"}, "b": []string{"2"}})
62 c.Check(err, gocheck.Equals, nil)62 c.Check(err, gocheck.Equals, nil)
63 c.Check(output, gocheck.Matches, "(a=1&b=2|b=2&a=1)")63 c.Check(output, gocheck.Matches, "(a=1&b=2)")
64}64}
6565
66// NormalizeParameters() escapes the parameters correctly when encoding66// NormalizeParameters() escapes the parameters correctly when encoding
@@ -84,5 +84,5 @@
84 }84 }
85 output, err := NormalizeParameters(params)85 output, err := NormalizeParameters(params)
86 c.Check(err, gocheck.Equals, nil)86 c.Check(err, gocheck.Equals, nil)
87 c.Check(output, gocheck.Matches, "(a=1&z=26|z=26&a=1)")87 c.Check(output, gocheck.Matches, "(a=1&z=26)")
88}88}
8989
=== modified file 'usso.go'
--- usso.go 2013-01-29 11:23:37 +0000
+++ usso.go 2013-02-05 12:38:20 +0000
@@ -49,7 +49,7 @@
49 "password": password,49 "password": password,
50 "token_name": tokenName,50 "token_name": tokenName,
51 }51 }
52 json_credentials, err := json.Marshal(credentials)52 jsonCredentials, err := json.Marshal(credentials)
53 if err != nil {53 if err != nil {
54 log.Printf("Error: %s\n", err)54 log.Printf("Error: %s\n", err)
55 return nil, err55 return nil, err
@@ -57,7 +57,7 @@
57 response, err := http.Post(57 response, err := http.Post(
58 server.tokenURL(),58 server.tokenURL(),
59 "application/json",59 "application/json",
60 strings.NewReader(string(json_credentials)))60 strings.NewReader(string(jsonCredentials)))
61 if err != nil {61 if err != nil {
62 return nil, err62 return nil, err
63 }63 }
@@ -77,14 +77,16 @@
7777
78// Returns all the Ubuntu SSO information related to this account.78// Returns all the Ubuntu SSO information related to this account.
79func (server UbuntuSSOServer) GetAccounts(ssodata *SSOData) (string, error) {79func (server UbuntuSSOServer) GetAccounts(ssodata *SSOData) (string, error) {
80 ssodata.BaseURL = server.AccountsURL() + ssodata.ConsumerKey80 rp := RequestParameters{
81 ssodata.HTTPMethod = "GET"81 BaseURL: server.AccountsURL() + ssodata.ConsumerKey,
82 ssodata.SignatureMethod = "HMAC-SHA1"82 HTTPMethod: "GET",
83 request, err := http.NewRequest(ssodata.HTTPMethod, ssodata.BaseURL, nil)83 SignatureMethod: HMACSHA1{}}
84
85 request, err := http.NewRequest(rp.HTTPMethod, rp.BaseURL, nil)
84 if err != nil {86 if err != nil {
85 return "", err87 return "", err
86 }88 }
87 err = SignRequest(ssodata, request)89 err = SignRequest(ssodata, &rp, request)
88 if err != nil {90 if err != nil {
89 return "", err91 return "", err
90 }92 }
@@ -103,12 +105,14 @@
103}105}
104106
105// Given oauth credentials and a request, return it signed.107// Given oauth credentials and a request, return it signed.
106func SignRequest(ssodata *SSOData, request *http.Request) error {108func SignRequest(
107 return ssodata.SignRequest(request)109 ssodata *SSOData, rp *RequestParameters, request *http.Request) error {
110 return ssodata.SignRequest(rp, request)
108}111}
109112
110// Given oauth credentials return a valid http authorization header.113// Given oauth credentials return a valid http authorization header.
111func GetAuthorizationHeader(ssodata *SSOData) (string, error) {114func GetAuthorizationHeader(
112 header, err := ssodata.GetAuthorizationHeader()115 ssodata *SSOData, rp *RequestParameters) (string, error) {
116 header, err := ssodata.GetAuthorizationHeader(rp)
113 return header, err117 return header, err
114}118}

Subscribers

People subscribed via source and target branches

to all changes: