martini-contrib / oauth2

[not maintained] Allows your Martini application to support user login via an OAuth 2.0 backend.
Apache License 2.0
125 stars 47 forks source link

Add profile getter #2

Open rakyll opened 10 years ago

jaredgisin commented 10 years ago

What is a "profile getter" ?

seedifferently commented 10 years ago

+1

Or at least some sort of hook we could use once the oauth handshake is completed so that we could do this ourselves...?

hansrodtang commented 10 years ago

I added this (probably somewhat ugly) hack to test this functionality and worked fine with Google atleast.

type Requests interface {
    Get(url string) []byte
}

type request struct {
    token
}

func (r *request) Get(url string) []byte {
    transport := &oauth.Transport{}
    transport.Token = &oauth.Token{r.AccessToken, r.RefreshToken, r.Expiry, r.Extra}

    resp, _ := transport.Client().Get(url)
    defer resp.Body.Close()
    body, _ := ioutil.ReadAll(resp.Body)
    return body
}
resp := request.Get("https://www.googleapis.com/plus/v1/people/me")
json.Unmarshal(resp, &profile)

in my function (with request oauth2.Requests via the injector)

Any comments on this method? Just returning the http.Client() would probably be better so people could easily add headers and POST, PUT, DELETE and whatever they might need. This was just a quick hack to test the idea.

hansrodtang commented 10 years ago

Authentication (who is the user) and authorisation (what am I allowed to do, which is the scope of the OAuth 2.0 standard) are pretty different things.

There isn't really anything called a OAuth2 profile and the data model of the profile on each different API (and scope) is pretty different.

Maybe it would help if we could define what was meant with a profile getter? What exact information from each service is it meant to retrieve? Simpe userID stuff or something a bit more complete? A full-fledged profile getter might be better served as a separate handler that depends on this one.

ahmetb commented 10 years ago

This shouldn't be in OAuth2 library logic.