Hello community, here is the log from the commit of package go-goauth2 for openSUSE:Factory checked in at 2012-01-19 09:41:48 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/go-goauth2 (Old) and /work/SRC/openSUSE:Factory/.go-goauth2.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "go-goauth2", Maintainer is "" Changes: -------- --- /work/SRC/openSUSE:Factory/go-goauth2/go-goauth2.changes 2011-10-07 00:47:36.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.go-goauth2.new/go-goauth2.changes 2012-01-19 09:41:49.000000000 +0100 @@ -1,0 +2,5 @@ +Tue Dec 13 15:31:07 UTC 2011 - sasc...@suse.de + +- Adjust to Go weekly.2011-12-02 release changes + +------------------------------------------------------------------- Old: ---- goauth2-0.0.0+hg20110813.tar.bz2 rpmlintrc New: ---- goauth2-0.0.0+hg20111205.tar.bz2 goauth2-weekly-fixes.patch ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ go-goauth2.spec ++++++ --- /var/tmp/diff_new_pack.MT41nq/_old 2012-01-19 09:41:50.000000000 +0100 +++ /var/tmp/diff_new_pack.MT41nq/_new 2012-01-19 09:41:50.000000000 +0100 @@ -2,7 +2,7 @@ # spec file for package go-goauth2 # # Copyright (c) 2011 SUSE LINUX Products GmbH, Nuernberg, Germany. -# Copyright (c), 2011, Sascha Peilicke <sasc...@gmx.de> +# Copyright (c) 2011 Sascha Peilicke <sasc...@gmx.de> # # All modifications and additions to the file contributed by third parties # remain the property of their copyright owners, unless otherwise agreed @@ -17,15 +17,15 @@ # - Name: go-goauth2 -Version: 0.0.0+hg20110813 -Release: 1 +Version: 0.0.0+hg20111205 +Release: 0 Summary: OAuth 2.0 for Go clients -Group: Development/Languages/Other License: MIT +Group: Development/Languages/Other Url: http://code.google.com/p/goauth2/ Source0: goauth2-%{version}.tar.bz2 +Patch0: goauth2-weekly-fixes.patch BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRequires: go-devel %{go_provides} @@ -37,18 +37,16 @@ %prep %setup -q -n goauth2 +%patch0 -p1 %build %install cd oauth && %{go_make_install} -%clean -rm -rf %{buildroot} - %files %defattr(-,root,root,-) -%doc oauth/example +%doc AUTHORS CONTRIBUTORS LICENSE oauth/example %{go_sitearch}/* %changelog ++++++ goauth2-0.0.0+hg20110813.tar.bz2 -> goauth2-0.0.0+hg20111205.tar.bz2 ++++++ Files old/goauth2/.hg/00changelog.i and new/goauth2/.hg/00changelog.i differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/branch new/goauth2/.hg/branch --- old/goauth2/.hg/branch 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/branch 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -default diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/cache/branchheads new/goauth2/.hg/cache/branchheads --- old/goauth2/.hg/cache/branchheads 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/cache/branchheads 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -1d1bf184962bfb6857eb4360e745adaef1390205 20 -1d1bf184962bfb6857eb4360e745adaef1390205 default diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/cache/tags new/goauth2/.hg/cache/tags --- old/goauth2/.hg/cache/tags 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/cache/tags 1970-01-01 01:00:00.000000000 +0100 @@ -1,5 +0,0 @@ -20 1d1bf184962bfb6857eb4360e745adaef1390205 dbd998807b7aad9a4682c2e357d90c61582a921f - -379476c9e05c5275356e0a82ca079e61869e9192 release -dfcfcf8893af73b581ed04be83ce405bd1e24f66 weekly.2011-08-17 -dfcfcf8893af73b581ed04be83ce405bd1e24f66 weekly Files old/goauth2/.hg/dirstate and new/goauth2/.hg/dirstate differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/hgrc new/goauth2/.hg/hgrc --- old/goauth2/.hg/hgrc 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/hgrc 1970-01-01 01:00:00.000000000 +0100 @@ -1,2 +0,0 @@ -[paths] -default = https://code.google.com/p/goauth2/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/requires new/goauth2/.hg/requires --- old/goauth2/.hg/requires 2011-10-06 16:06:23.000000000 +0200 +++ new/goauth2/.hg/requires 1970-01-01 01:00:00.000000000 +0100 @@ -1,4 +0,0 @@ -revlogv1 -store -fncache -dotencode Files old/goauth2/.hg/store/00changelog.i and new/goauth2/.hg/store/00changelog.i differ Files old/goauth2/.hg/store/00manifest.i and new/goauth2/.hg/store/00manifest.i differ Files old/goauth2/.hg/store/data/_c_o_n_t_r_i_b_u_t_o_r_s.i and new/goauth2/.hg/store/data/_c_o_n_t_r_i_b_u_t_o_r_s.i differ Files old/goauth2/.hg/store/data/lib/codereview/codereview.cfg.i and new/goauth2/.hg/store/data/lib/codereview/codereview.cfg.i differ Files old/goauth2/.hg/store/data/oauth/_makefile.i and new/goauth2/.hg/store/data/oauth/_makefile.i differ Files old/goauth2/.hg/store/data/oauth/example/_makefile.i and new/goauth2/.hg/store/data/oauth/example/_makefile.i differ Files old/goauth2/.hg/store/data/oauth/example/buzz.go.i and new/goauth2/.hg/store/data/oauth/example/buzz.go.i differ Files old/goauth2/.hg/store/data/oauth/oauth.go.i and new/goauth2/.hg/store/data/oauth/oauth.go.i differ Files old/goauth2/.hg/store/data/~2ehgtags.i and new/goauth2/.hg/store/data/~2ehgtags.i differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/store/fncache new/goauth2/.hg/store/fncache --- old/goauth2/.hg/store/fncache 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/store/fncache 1970-01-01 01:00:00.000000000 +0100 @@ -1,7 +0,0 @@ -data/oauth/example/Makefile.i -data/CONTRIBUTORS.i -data/oauth/example/buzz.go.i -data/.hgtags.i -data/lib/codereview/codereview.cfg.i -data/oauth/Makefile.i -data/oauth/oauth.go.i Files old/goauth2/.hg/store/undo and new/goauth2/.hg/store/undo differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/undo.branch new/goauth2/.hg/undo.branch --- old/goauth2/.hg/undo.branch 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/undo.branch 1970-01-01 01:00:00.000000000 +0100 @@ -1 +0,0 @@ -default \ No newline at end of file diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hg/undo.desc new/goauth2/.hg/undo.desc --- old/goauth2/.hg/undo.desc 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hg/undo.desc 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ -0 -pull -https://code.google.com/p/goauth2/ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/.hgtags new/goauth2/.hgtags --- old/goauth2/.hgtags 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/.hgtags 1970-01-01 01:00:00.000000000 +0100 @@ -1,3 +0,0 @@ -379476c9e05c5275356e0a82ca079e61869e9192 release -dfcfcf8893af73b581ed04be83ce405bd1e24f66 weekly.2011-08-17 -dfcfcf8893af73b581ed04be83ce405bd1e24f66 weekly diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/AUTHORS new/goauth2/AUTHORS --- old/goauth2/AUTHORS 1970-01-01 01:00:00.000000000 +0100 +++ new/goauth2/AUTHORS 2011-12-05 16:44:44.000000000 +0100 @@ -0,0 +1,11 @@ +# This is the official list of goauth2 authors for copyright purposes. +# This file is distinct from the CONTRIBUTORS files. +# See the latter for an explanation. + +# Names should be added to this file as +# Name or Organization <email address> +# The email address is not required for organizations. + +# Please keep the list sorted. + +Google Inc. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/CONTRIBUTORS new/goauth2/CONTRIBUTORS --- old/goauth2/CONTRIBUTORS 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/CONTRIBUTORS 2011-12-05 16:44:44.000000000 +0100 @@ -1,2 +1,36 @@ +# This is the official list of people who can contribute +# (and typically have contributed) code to the goauth2 repository. +# The AUTHORS file lists the copyright holders; this file +# lists people. For example, Google employees are listed here +# but not in AUTHORS, because Google holds the copyright. +# +# The submission process automatically checks to make sure +# that people submitting code are listed in this file (by email address). +# +# Names should be added to this file only after verifying that +# the individual or the individual's organization has agreed to +# the appropriate Contributor License Agreement, found here: +# +# http://code.google.com/legal/individual-cla-v1.0.html +# http://code.google.com/legal/corporate-cla-v1.0.html +# +# The agreement for individuals can be filled out on the web. +# +# When adding J Random Contributor's name to this file, +# either J's name or J's organization's name should be +# added to the AUTHORS file, depending on whether the +# individual or corporate CLA was used. + +# Names should be added to this file like so: +# Name <email address> +# +# An entry with two email addresses specifies that the +# first address should be used in the submit logs and +# that the second address should be recognized as the +# same person when interacting with Rietveld. + +# Please keep the list sorted. + Andrew Gerrand <a...@golang.org> Brad Fitzpatrick <bradf...@golang.org> +Manu Garg <manug...@google.com> diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/LICENSE new/goauth2/LICENSE --- old/goauth2/LICENSE 1970-01-01 01:00:00.000000000 +0100 +++ new/goauth2/LICENSE 2011-12-05 16:44:44.000000000 +0100 @@ -0,0 +1,27 @@ +Copyright (c) 2009 The goauth2 Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + * Redistributions of source code must retain the above copyright +notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above +copyright notice, this list of conditions and the following disclaimer +in the documentation and/or other materials provided with the +distribution. + * Neither the name of Google Inc. nor the names of its +contributors may be used to endorse or promote products derived from +this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/PATENTS new/goauth2/PATENTS --- old/goauth2/PATENTS 1970-01-01 01:00:00.000000000 +0100 +++ new/goauth2/PATENTS 2011-12-05 16:44:44.000000000 +0100 @@ -0,0 +1,22 @@ +Additional IP Rights Grant (Patents) + +"This implementation" means the copyrightable works distributed by +Google as part of the goauth2 project. + +Google hereby grants to You a perpetual, worldwide, non-exclusive, +no-charge, royalty-free, irrevocable (except as stated in this section) +patent license to make, have made, use, offer to sell, sell, import, +transfer and otherwise run, modify and propagate the contents of this +implementation of Go, where such license applies only to those patent +claims, both currently owned or controlled by Google and acquired in +the future, licensable by Google that are necessarily infringed by this +implementation of Go. This grant does not include claims that would be +infringed only as a consequence of further modification of this +implementation. If you or your agent or exclusive licensee institute or +order or agree to the institution of patent litigation against any +entity (including a cross-claim or counterclaim in a lawsuit) alleging +that this implementation of Go or any code incorporated within this +implementation of Go constitutes direct or contributory patent +infringement, or inducement of patent infringement, then any patent +rights granted to you under this License for this implementation of Go +shall terminate as of the date such litigation is filed. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/oauth/Makefile new/goauth2/oauth/Makefile --- old/goauth2/oauth/Makefile 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/oauth/Makefile 2011-12-05 16:44:44.000000000 +0100 @@ -1,4 +1,4 @@ -# Copyright 2011 The Go Authors. All rights reserved. +# Copyright 2011 The goauth2 Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/oauth/example/Makefile new/goauth2/oauth/example/Makefile --- old/goauth2/oauth/example/Makefile 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/oauth/example/Makefile 2011-12-05 16:44:44.000000000 +0100 @@ -1,4 +1,4 @@ -# Copyright 2011 The Go Authors. All rights reserved. +# Copyright 2011 The goauth2 Authors. All rights reserved. # Use of this source code is governed by a BSD-style # license that can be found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/oauth/example/buzz.go new/goauth2/oauth/example/buzz.go --- old/goauth2/oauth/example/buzz.go 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/oauth/example/buzz.go 2011-12-05 16:44:44.000000000 +0100 @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The goauth2 Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/goauth2/oauth/oauth.go new/goauth2/oauth/oauth.go --- old/goauth2/oauth/oauth.go 2011-10-06 16:06:24.000000000 +0200 +++ new/goauth2/oauth/oauth.go 2011-12-05 16:44:44.000000000 +0100 @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The goauth2 Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -174,11 +174,7 @@ // Refresh the Token if it has expired. if t.Expired() { - err := t.updateToken(t.Token, url.Values{ - "grant_type": {"refresh_token"}, - "refresh_token": {t.RefreshToken}, - }) - if err != nil { + if err := t.Refresh(); err != nil { return nil, err } } @@ -188,6 +184,20 @@ return t.transport().RoundTrip(req) } +// Refresh renews the Transport's AccessToken using its RefreshToken. +func (t *Transport) Refresh() os.Error { + if t.Config == nil { + return os.NewError("no Config supplied") + } else if t.Token == nil { + return os.NewError("no exisiting Token") + } + + return t.updateToken(t.Token, url.Values{ + "grant_type": {"refresh_token"}, + "refresh_token": {t.RefreshToken}, + }) +} + func (t *Transport) updateToken(tok *Token, v url.Values) os.Error { v.Set("client_id", t.ClientId) v.Set("client_secret", t.ClientSecret) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/oauth/Makefile new/oauth/Makefile --- old/oauth/Makefile 2011-10-06 16:06:24.000000000 +0200 +++ new/oauth/Makefile 1970-01-01 01:00:00.000000000 +0100 @@ -1,11 +0,0 @@ -# Copyright 2011 The Go Authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - -include $(GOROOT)/src/Make.inc - -TARG=goauth2.googlecode.com/hg/oauth -GOFILES=\ - oauth.go\ - -include $(GOROOT)/src/Make.pkg diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/oauth/example/Makefile new/oauth/example/Makefile --- old/oauth/example/Makefile 2011-10-06 16:06:24.000000000 +0200 +++ new/oauth/example/Makefile 1970-01-01 01:00:00.000000000 +0100 @@ -1,11 +0,0 @@ -# Copyright 2011 The Go Authors. All rights reserved. -# Use of this source code is governed by a BSD-style -# license that can be found in the LICENSE file. - -include $(GOROOT)/src/Make.inc - -TARG=buzz -GOFILES=\ - buzz.go\ - -include $(GOROOT)/src/Make.cmd diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/oauth/example/buzz.go new/oauth/example/buzz.go --- old/oauth/example/buzz.go 2011-10-06 16:06:24.000000000 +0200 +++ new/oauth/example/buzz.go 1970-01-01 01:00:00.000000000 +0100 @@ -1,95 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This program makes a call to the buzz API, authenticated with OAuth2. -package main - -import ( - "flag" - "fmt" - "io" - "log" - "os" - - "goauth2.googlecode.com/hg/oauth" -) - -var ( - code = flag.String("code", "", "Authorization Code") - token = flag.String("token", "", "Access Token") - clientId = flag.String("id", "", "Client ID") - clientSecret = flag.String("secret", "", "Client Secret") -) - -const usageMsg = ` -You must specify at least -id and -secret. -To obtain these details, see the "OAuth 2 Credentials" section under -the "API Access" tab on this page: https://code.google.com/apis/console/ -` - -const activities = "https://www.googleapis.com/buzz/v1/activities/@me/@public?max-results=1&alt=json" - -func main() { - flag.Parse() - if *clientId == "" || *clientSecret == "" { - flag.Usage() - fmt.Fprint(os.Stderr, usageMsg) - return - } - - // Set up a configuration - config := &oauth.Config{ - ClientId: *clientId, - ClientSecret: *clientSecret, - Scope: "https://www.googleapis.com/auth/buzz", - AuthURL: "https://accounts.google.com/o/oauth2/auth", - TokenURL: "https://accounts.google.com/o/oauth2/token", - RedirectURL: "http://localhost/", - } - - // Step one, get an authorization code from the data provider. - // ("Please ask the user if I can access this resource.") - if *code == "" && *token == "" { - url := config.AuthCodeURL("") - fmt.Println("Visit this URL to get a code, then run again with -code=YOUR_CODE") - fmt.Println(url) - return - } - - // Set up a Transport with our config. - t := &oauth.Transport{Config: config} - - // Step two, exchange the authorization code for an access token. - // ("Here's the code you gave the user, now give me a token!") - if *token == "" { - tok, err := t.Exchange(*code) - if err != nil { - log.Fatal(err) - } - fmt.Printf("Now run again with -token=%s\n", tok.AccessToken) - return - // We needn't return here; we could just use the Transport - // to make authenticated requests straight away. - // The process has been split up to demonstrate how one might - // restore Credentials that have been previously stored. - } - - // Step three, make the actual request using the token to authenticate. - // ("Here's the token, let me in!") - // First, re-instate our Token (typically this would be stored on disk). - t.Token = &oauth.Token{ - AccessToken: *token, - // If you were storing this information somewhere, - // you'd want to store the RefreshToken field as well. - } - // Make the request. - r, err := t.Client().Get(activities) - if err != nil { - log.Fatal(err) - } - defer r.Body.Close() - // Write the response to standard output. - io.Copy(os.Stdout, r.Body) - fmt.Println() -} diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/oauth/oauth.go new/oauth/oauth.go --- old/oauth/oauth.go 2011-10-06 16:06:24.000000000 +0200 +++ new/oauth/oauth.go 1970-01-01 01:00:00.000000000 +0100 @@ -1,209 +0,0 @@ -// Copyright 2011 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// The oauth package provides support for making -// OAuth2-authenticated HTTP requests. -// -// Example usage: -// -// // Specify your configuration. (typically as a global variable) -// var config = &oauth.Config{ -// ClientId: YOUR_CLIENT_ID, -// ClientSecret: YOUR_CLIENT_SECRET, -// Scope: "https://www.googleapis.com/auth/buzz", -// AuthURL: "https://accounts.google.com/o/oauth2/auth", -// TokenURL: "https://accounts.google.com/o/oauth2/token", -// RedirectURL: "http://you.example.org/handler", -// } -// -// // A landing page redirects to the OAuth provider to get the auth code. -// func landing(w http.ResponseWriter, r *http.Request) { -// http.Redirect(w, r, config.AuthCodeURL("foo"), http.StatusFound) -// } -// -// // The user will be redirected back to this handler, that takes the -// // "code" query parameter and Exchanges it for an access token. -// func handler(w http.ResponseWriter, r *http.Request) { -// t := &oauth.Transport{Config: config} -// t.Exchange(r.FormValue("code")) -// // The Transport now has a valid Token. Create an *http.Client -// // with which we can make authenticated API requests. -// c := t.Client() -// c.Post(...) -// // ... -// // btw, r.FormValue("state") == "foo" -// } -// -package oauth - -// TODO(adg): A means of automatically saving credentials when updated. - -import ( - "http" - "json" - "os" - "time" - "url" -) - -// Config is the configuration of an OAuth consumer. -type Config struct { - ClientId string - ClientSecret string - Scope string - AuthURL string - TokenURL string - RedirectURL string // Defaults to out-of-band mode if empty. -} - -func (c *Config) redirectURL() string { - if c.RedirectURL != "" { - return c.RedirectURL - } - return "oob" -} - -// Token contains an end-user's tokens. -// This is the data you must store to persist authentication. -type Token struct { - AccessToken string `json:"access_token"` - RefreshToken string `json:"refresh_token"` - - // TokenExpiry is a unix timestamp in seconds that indicates when the - // token will expire. Zero means the token has no (known) expiry time. - // (Note: this is not the expires_in field as per the spec, - // even though we unmarshal the JSON expires_in value into this field.) - TokenExpiry int64 `json:"expires_in"` -} - -func (t *Token) Expired() bool { - if t.TokenExpiry == 0 { - return false - } - return t.TokenExpiry <= time.Seconds() -} - -// Transport implements http.RoundTripper. When configured with a valid -// Config and Token it can be used to make authenticated HTTP requests. -// -// t := &oauth.Transport{config} -// t.Exchange(code) -// // t now contains a valid Token -// r, _, err := t.Client().Get("http://example.org/url/requiring/auth") -// -// It will automatically refresh the Token if it can, -// updating the supplied Token in place. -type Transport struct { - *Config - *Token - - // Transport is the HTTP transport to use when making requests. - // It will default to http.DefaultTransport if nil. - // (It should never be an oauth.Transport.) - Transport http.RoundTripper -} - -// Client returns an *http.Client that makes OAuth-authenticated requests. -func (t *Transport) Client() *http.Client { - return &http.Client{Transport: t} -} - -func (t *Transport) transport() http.RoundTripper { - if t.Transport != nil { - return t.Transport - } - return http.DefaultTransport -} - -// AuthCodeURL returns a URL that the end-user should be redirected to, -// so that they may obtain an authorization code. -func (c *Config) AuthCodeURL(state string) string { - url_, err := url.Parse(c.AuthURL) - if err != nil { - panic("AuthURL malformed: " + err.String()) - } - q := url.Values{ - "response_type": {"code"}, - "client_id": {c.ClientId}, - "redirect_uri": {c.redirectURL()}, - "scope": {c.Scope}, - "state": {state}, - }.Encode() - if url_.RawQuery == "" { - url_.RawQuery = q - } else { - url_.RawQuery += "&" + q - } - return url_.String() -} - -// Exchange takes a code and gets access Token from the remote server. -func (t *Transport) Exchange(code string) (tok *Token, err os.Error) { - if t.Config == nil { - return nil, os.NewError("no Config supplied") - } - tok = new(Token) - err = t.updateToken(tok, url.Values{ - "grant_type": {"authorization_code"}, - "redirect_uri": {t.redirectURL()}, - "scope": {t.Scope}, - "code": {code}, - }) - if err == nil { - t.Token = tok - } - return -} - -// RoundTrip executes a single HTTP transaction using the Transport's -// Token as authorization headers. -// -// This method will attempt to renew the Token if it has expired and may return -// an error related to that Token renewal before attempting the client request. -// If the Token cannot be renewed a non-nil os.Error value will be returned. -// If the Token is invalid callers should expect HTTP-level errors, -// as indicated by the Response's StatusCode. -func (t *Transport) RoundTrip(req *http.Request) (*http.Response, os.Error) { - if t.Config == nil { - return nil, os.NewError("no Config supplied") - } - if t.Token == nil { - return nil, os.NewError("no Token supplied") - } - - // Refresh the Token if it has expired. - if t.Expired() { - err := t.updateToken(t.Token, url.Values{ - "grant_type": {"refresh_token"}, - "refresh_token": {t.RefreshToken}, - }) - if err != nil { - return nil, err - } - } - - // Make the HTTP request. - req.Header.Set("Authorization", "OAuth "+t.AccessToken) - return t.transport().RoundTrip(req) -} - -func (t *Transport) updateToken(tok *Token, v url.Values) os.Error { - v.Set("client_id", t.ClientId) - v.Set("client_secret", t.ClientSecret) - r, err := (&http.Client{Transport: t.transport()}).PostForm(t.TokenURL, v) - if err != nil { - return err - } - defer r.Body.Close() - if r.StatusCode != 200 { - return os.NewError("invalid response: " + r.Status) - } - if err = json.NewDecoder(r.Body).Decode(tok); err != nil { - return err - } - if tok.TokenExpiry != 0 { - tok.TokenExpiry = time.Seconds() + tok.TokenExpiry - } - return nil -} ++++++ goauth2-weekly-fixes.patch ++++++ diff -ru a/oauth/oauth.go b/oauth/oauth.go --- a/oauth/oauth.go 2011-12-05 16:44:44.000000000 +0100 +++ b/oauth/oauth.go 2011-12-13 16:30:26.876564888 +0100 @@ -40,11 +40,12 @@ // TODO(adg): A means of automatically saving credentials when updated. import ( - "http" - "json" - "os" + "encoding/json" + "errors" + "net/http" + + "net/url" "time" - "url" ) // Config is the configuration of an OAuth consumer. @@ -81,7 +82,7 @@ if t.TokenExpiry == 0 { return false } - return t.TokenExpiry <= time.Seconds() + return t.TokenExpiry <= time.Now().Unix() } // Transport implements http.RoundTripper. When configured with a valid @@ -121,7 +122,7 @@ func (c *Config) AuthCodeURL(state string) string { url_, err := url.Parse(c.AuthURL) if err != nil { - panic("AuthURL malformed: " + err.String()) + panic("AuthURL malformed: " + err.Error()) } q := url.Values{ "response_type": {"code"}, @@ -139,9 +140,9 @@ } // Exchange takes a code and gets access Token from the remote server. -func (t *Transport) Exchange(code string) (tok *Token, err os.Error) { +func (t *Transport) Exchange(code string) (tok *Token, err error) { if t.Config == nil { - return nil, os.NewError("no Config supplied") + return nil, errors.New("no Config supplied") } tok = new(Token) err = t.updateToken(tok, url.Values{ @@ -164,12 +165,12 @@ // If the Token cannot be renewed a non-nil os.Error value will be returned. // If the Token is invalid callers should expect HTTP-level errors, // as indicated by the Response's StatusCode. -func (t *Transport) RoundTrip(req *http.Request) (*http.Response, os.Error) { +func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error) { if t.Config == nil { - return nil, os.NewError("no Config supplied") + return nil, errors.New("no Config supplied") } if t.Token == nil { - return nil, os.NewError("no Token supplied") + return nil, errors.New("no Token supplied") } // Refresh the Token if it has expired. @@ -185,11 +186,11 @@ } // Refresh renews the Transport's AccessToken using its RefreshToken. -func (t *Transport) Refresh() os.Error { +func (t *Transport) Refresh() error { if t.Config == nil { - return os.NewError("no Config supplied") + return errors.New("no Config supplied") } else if t.Token == nil { - return os.NewError("no exisiting Token") + return errors.New("no exisiting Token") } return t.updateToken(t.Token, url.Values{ @@ -198,7 +199,7 @@ }) } -func (t *Transport) updateToken(tok *Token, v url.Values) os.Error { +func (t *Transport) updateToken(tok *Token, v url.Values) error { v.Set("client_id", t.ClientId) v.Set("client_secret", t.ClientSecret) r, err := (&http.Client{Transport: t.transport()}).PostForm(t.TokenURL, v) @@ -207,13 +208,13 @@ } defer r.Body.Close() if r.StatusCode != 200 { - return os.NewError("invalid response: " + r.Status) + return errors.New("invalid response: " + r.Status) } if err = json.NewDecoder(r.Body).Decode(tok); err != nil { return err } if tok.TokenExpiry != 0 { - tok.TokenExpiry = time.Seconds() + tok.TokenExpiry + tok.TokenExpiry = time.Now().Unix() + tok.TokenExpiry } return nil } Only in b/oauth: .oauth.go.swp -- To unsubscribe, e-mail: opensuse-commit+unsubscr...@opensuse.org For additional commands, e-mail: opensuse-commit+h...@opensuse.org