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

Proposed by Vincenzo Di Somma
Status: Merged
Approved by: Casey Marshall
Approved revision: 30
Merged at revision: 30
Proposed branch: lp:~vds/usso/kind_of_login
Merge into: lp:usso
Diff against target: 125 lines (+67/-5)
3 files modified
example/usso_example.go (+2/-3)
usso.go (+36/-1)
usso_test.go (+29/-1)
To merge this branch: bzr merge lp:~vds/usso/kind_of_login
Reviewer Review Type Date Requested Status
Casey Marshall (community) Approve
Review via email: mp+193462@code.launchpad.net

Commit message

Adding support for getting token details.

Description of the change

Adding support for getting token details.

To post a comment you must log in.
Revision history for this message
Casey Marshall (cmars) wrote :

I updated my usso_test app to evaluate the contents of the token details, and it seems to work well with the following test.

Using https://bazaar.launchpad.net/~cmars/+junk/usso_test/view/head:/main.go, I signed into usso, authorizing the test application token, "test-usso-token". The resulting auth string was valid when checked against USSO, token details were thus:

{
    "token_name": "test-usso-token",
    "date_updated": "2013-10-31T19:28:50.268",
    "token_key": "[redacted]",
    "href": "/api/v2/tokens/oauth/[redacted, same as token_key's value]",
    "date_created": "2013-10-31T19:28:50.268",
    "consumer_key": "[redacted]"
}

Then I went to the Applications tab on login.ubuntu.com and test-usso-token was listed as an authorized application. I deleted the authorization there, and a subsequent USSO query with the auth string came back with token details:

{"message": "Provided email/password is not correct.", "code": "INVALID_CREDENTIALS", "extra": {}}

This looks very good to me!

review: Approve

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-02-05 12:37:03 +0000
+++ example/usso_example.go 2013-10-31 17:37:25 +0000
@@ -23,12 +23,9 @@
2323
24func main() {24func main() {
25 inputParams()25 inputParams()
26
27 // Fetch the tokens using usso.GetToken.26 // Fetch the tokens using usso.GetToken.
28 fmt.Println("Fetching tokens from staging server...")27 fmt.Println("Fetching tokens from staging server...")
29 server := usso.StagingUbuntuSSOServer28 server := usso.StagingUbuntuSSOServer
30 // One would use server := usso.ProductionUbuntuSSOServer
31 // to use the production Ubuntu SSO Server.
32 ssodata, err := server.GetToken(email, password, "usso")29 ssodata, err := server.GetToken(email, password, "usso")
33 if err != nil {30 if err != nil {
34 panic(err)31 panic(err)
@@ -67,4 +64,6 @@
67 var b bytes.Buffer64 var b bytes.Buffer
68 b.Write(body)65 b.Write(body)
69 fmt.Printf("response: %+v\n", b.String())66 fmt.Printf("response: %+v\n", b.String())
67 token_details, _ := server.GetTokenDetails(ssodata)
68 fmt.Printf("token details: %s\n", token_details)
70}69}
7170
=== modified file 'usso.go'
--- usso.go 2013-02-27 15:14:29 +0000
+++ usso.go 2013-10-31 17:37:25 +0000
@@ -20,12 +20,18 @@
20 return server.baseUrl + "/api/v2/tokens/oauth"20 return server.baseUrl + "/api/v2/tokens/oauth"
21}21}
2222
23// AccountURL returns the URL where the Ubuntu SSO account information can be 23// AccountURL returns the URL where the Ubuntu SSO account information can be
24// requested.24// requested.
25func (server UbuntuSSOServer) AccountsURL() string {25func (server UbuntuSSOServer) AccountsURL() string {
26 return server.baseUrl + "/api/v2/accounts/"26 return server.baseUrl + "/api/v2/accounts/"
27}27}
2828
29// TokenDetailURL returns the URL where the Ubuntu SSO token details can be
30// requested.
31func (server UbuntuSSOServer) TokenDetailsURL() string {
32 return server.baseUrl + "/api/v2/tokens/oauth/"
33}
34
29// ProductionUbuntuSSOServer represents the production Ubuntu SSO server35// ProductionUbuntuSSOServer represents the production Ubuntu SSO server
30// located at https://login.ubuntu.com.36// located at https://login.ubuntu.com.
31var ProductionUbuntuSSOServer = UbuntuSSOServer{"https://login.ubuntu.com"}37var ProductionUbuntuSSOServer = UbuntuSSOServer{"https://login.ubuntu.com"}
@@ -116,3 +122,32 @@
116 header, err := ssodata.GetAuthorizationHeader(rp)122 header, err := ssodata.GetAuthorizationHeader(rp)
117 return header, err123 return header, err
118}124}
125
126// Returns all the Ubuntu SSO information related to this token.
127func (server UbuntuSSOServer) GetTokenDetails(ssodata *SSOData) (string, error) {
128 rp := RequestParameters{
129 BaseURL: server.TokenDetailsURL() + ssodata.TokenKey,
130 HTTPMethod: "GET",
131 SignatureMethod: HMACSHA1{}}
132
133 request, err := http.NewRequest(rp.HTTPMethod, rp.BaseURL, nil)
134 if err != nil {
135 return "", err
136 }
137 err = SignRequest(ssodata, &rp, request)
138 if err != nil {
139 return "", err
140 }
141 client := &http.Client{}
142 response, err := client.Do(request)
143 if err != nil {
144 fmt.Printf("Error: %s\n", err)
145 }
146 body, err := ioutil.ReadAll(response.Body)
147 if err != nil {
148 fmt.Println(err)
149 }
150 var b bytes.Buffer
151 b.Write(body)
152 return fmt.Sprint(b.String()), nil
153}
119154
=== modified file 'usso_test.go'
--- usso_test.go 2013-02-27 15:14:29 +0000
+++ usso_test.go 2013-10-31 17:37:25 +0000
@@ -99,7 +99,7 @@
99 ConsumerSecret: consumerSecret, TokenKey: tokenKey,99 ConsumerSecret: consumerSecret, TokenKey: tokenKey,
100 TokenSecret: tokenSecret, TokenName: tokenName}100 TokenSecret: tokenSecret, TokenName: tokenName}
101 c.Assert(ssodata, DeepEquals, expectedSSOData)101 c.Assert(ssodata, DeepEquals, expectedSSOData)
102 //The request that the fake Ubuntu SSO Server got contained the credentials.102 // The request that the fake Ubuntu SSO Server has the credentials.
103 credentials := map[string]string{103 credentials := map[string]string{
104 "email": email,104 "email": email,
105 "password": password,105 "password": password,
@@ -122,3 +122,31 @@
122 c.Assert(err, NotNil)122 c.Assert(err, NotNil)
123 c.Assert(ssodata, IsNil)123 c.Assert(ssodata, IsNil)
124}124}
125
126func (suite *USSOTestSuite) TestGetTokenDetails(c *C) {
127 // Simulate a valid Ubuntu SSO Server response.
128 serverResponseData := map[string]string{
129 "date_updated": "2013-01-16 14:03:36",
130 "date_created": "2013-01-16 14:03:36",
131 "href": "/api/v2/tokens/" + tokenKey,
132 "token_name": tokenName,
133 "token_key": tokenKey,
134 "consumer_key": consumerKey,
135 }
136 jsonServerResponseData, err := json.Marshal(serverResponseData)
137 if err != nil {
138 panic(err)
139 }
140 server := newSingleServingServer("/api/v2/tokens/oauth",
141 string(jsonServerResponseData), 200)
142 var testSSOServer = &UbuntuSSOServer{server.URL}
143 defer server.Close()
144 ssodata, err := testSSOServer.GetToken(email, password, tokenName)
145
146 // The returned information is correct.
147 token_details, err := testSSOServer.GetTokenDetails(ssodata)
148 c.Assert(err, IsNil)
149
150 //The request that the fake Ubuntu SSO Server has the token details.
151 fmt.Printf("%s\n", token_details)
152}

Subscribers

People subscribed via source and target branches

to all changes: