Skip to content

Commit

Permalink
Merge pull request openshift#96 from knq/master
Browse files Browse the repository at this point in the history
Updating goauth2client example to use newer golang.net/x/oauth2 package
  • Loading branch information
RangelReale committed Nov 24, 2015
2 parents 7da44eb + 415d174 commit d47a3d4
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions example/goauth2client/goauth2client.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package main

// Use code.google.com/p/goauth2/oauth client to test
// Use golang.org/x/oauth2 client to test
// Open url in browser:
// http://localhost:14000/app

import (
"code.google.com/p/goauth2/oauth"
"fmt"
"net/http"

"github.com/RangelReale/osin"
"github.com/RangelReale/osin/example"
"net/http"
"golang.org/x/oauth2"
)

func main() {
Expand All @@ -19,14 +20,15 @@ func main() {

server := osin.NewServer(config, example.NewTestStorage())

client := &oauth.Config{
ClientId: "1234",
client := &oauth2.Config{
ClientID: "1234",
ClientSecret: "aabbccdd",
RedirectURL: "http://localhost:14000/appauth/code",
AuthURL: "http://localhost:14000/authorize",
TokenURL: "http://localhost:14000/token",
Endpoint: oauth2.Endpoint{
AuthURL: "http://localhost:14000/authorize",
TokenURL: "http://localhost:14000/token",
},
RedirectURL: "http://localhost:14000/appauth/code",
}
ctransport := &oauth.Transport{Config: client}

// Authorization code endpoint
http.HandleFunc("/authorize", func(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -95,12 +97,12 @@ func main() {
return
}

var jr *oauth.Token
var jr *oauth2.Token
var err error

// if parse, download and parse json
if r.Form.Get("doparse") == "1" {
jr, err = ctransport.Exchange(code)
jr, err = client.Exchange(oauth2.NoContext, code)
if err != nil {
jr = nil
w.Write([]byte(fmt.Sprintf("ERROR: %s<br/>\n", err)))
Expand Down

0 comments on commit d47a3d4

Please sign in to comment.