GOAuth [Go package]
GOauth is a OAuth Consumer package for the Go Programming language.
#> goinstall github.com/hokapoka/goauth
The package is available on github and can be install with goinstall, as shown above. Once installed you are able to make requests to OAuth services.
The version is 1.0 protocol as per the RFC 5849 document : [http://tools.ietf.org/html/rfc5849].
type OAuthConsumer struct
The OAuthConsumer has a number of exported fields these are:
- Service
- Is just a string for to indicate the service that is being used, currently has no technical usage.
- RequestTokenURL
- The URL of the service to get a new Request Token from.
- AccessTokenURL
- The URL of the service to get the AccessToken for the Confirmed RequestToken
- AuthorizationURL
- The URL of the service that the account must used to Authorize the Request For Access
- ConsumerKey
- The Consumer Key for the OAuth Client from the Service
- ConsumerSecret
- The Consumer Secret for the OAuth Client from the Service
- CallBackURL
- The URL that the OAuth service should use
These are the Exported Methods:
- func (oc *OAuthConsumer) GetRequestAuthorizationURL() (string, os.Error)
- GetRequestAuthorizationURL Returns the URL for the visitor to Authorize the Access, or an error.
- func (oc *OAuthConsumer) GetAccessToken(token string, verifier string, ) *AccessToken
- GetAccessToken gets the access token for the response from the Authorization URL. Where token & verifier are the strings returned from the service to the CallBackURL.
- func (oc *OAuthConsumer) Get( url string, at *AccessToken) (r *http.Response, err os.Error)
- Get returns the response via a GET for the url with the AccessToken passed, or an error.
- func (oc *OAuthConsumer) Post( url string, fparams Params, at *AccessToken) (r *http.Response, err os.Error)
- Post returns the response via a POST for the url with the AccessToken passed & the Form params passsed in fparams, or an error
type AccessToken struct
The AccessToken, returned from GetAccessToken, Is to be used for all subsequent requests for the authorized user.
There, currently, is no built-in persistence for these tokens. This means you will have to store the AccessToken in some way such as using mongoDB or a file, and associate it with a given user on your system. There is an unused exported field UserRef string that can be used for this purpose, if necessary.
Example
There are a handful of example within the source of the package but there’s a more details walk through of Creating an basic Out Of Band OAuth Twitter client.
looking around quickly, I haven’t seen info on which OAuth version you have implemented?
Hi mateusz
You’re right there’s no indication which OAuth version it implements.
The version is 1.0 protocol as per the RFC 5849 document [http://tools.ietf.org/html/rfc5849].
Thanks for pointing that out, the page has now been updated to include the version.
We’re about finished implementing the 2.0 as per : http://tools.ietf.org/html/draft-ietf-oauth-v2-10 but we have a few loose ends with this revision before we release that.
If you are interested in using the 2.0 implementation let us know and we’ll happily give you the source to try out.
Many thanks.
Looking forward to the example!
Hey Jason, I’ve added a simple Out Of Band Mode Example.
There are 3 other examples in the GOAuth package on Github, using both OOB and HTTP web services.
There’s also a Google Buzz Example.
Hi,
I tried installing goauth using goinstall
goinstall github.com/hokapoka/goauth
But I am getting the following error !
Help Please
goinstall: === cd /home/chinmay/NewGo/go/src/pkg/github.com/hokapoka/goauth; gomake -f- install
6g -o _go_.6 http.go oauth.go pairs.go urlencode.go oauthconsumer.go token.go
http.go:104: too many arguments in call to net.Dial
http.go:106: cannot use addr (type string) as type *tls.Config in function argument
http.go:106: too many arguments in call to tls.Dial
make: *** [_go_.6] Error 1
— exit status 2
goinstall: installing github.com/hokapoka/goauth: running gomake: exit status 2