-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Allen Flickinger
committed
Nov 1, 2020
1 parent
011f76b
commit 3982a82
Showing
4 changed files
with
281 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/FuzzyStatic/blizzard/v1" | ||
"github.com/FuzzyStatic/blizzard/v1/oauth" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
var ( | ||
clientID string | ||
clientSecret string | ||
myDomain string | ||
cfg oauth2.Config | ||
blizz *blizzard.Client | ||
) | ||
|
||
func homepage(w http.ResponseWriter, r *http.Request) { | ||
fmt.Println("Homepage Hit!") | ||
http.Redirect(w, r, cfg.AuthCodeURL("my_random_state"), http.StatusFound) | ||
} | ||
|
||
func authorize(w http.ResponseWriter, r *http.Request) { | ||
err := r.ParseForm() | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
state := r.Form.Get("state") | ||
if state != "my_random_state" { | ||
http.Error(w, "State invalid", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
code := r.Form.Get("code") | ||
if code == "" { | ||
http.Error(w, "Code not found", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
token, err := cfg.Exchange(context.Background(), code) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
e := json.NewEncoder(w) | ||
e.SetIndent("", " ") | ||
err = e.Encode(*token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
validation, _, err := blizz.TokenValidation(token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
|
||
fmt.Printf("%+v\n", validation) | ||
|
||
userInfo, _, err := blizz.UserInfoHeader(token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
|
||
fmt.Printf("%+v\n", userInfo) | ||
} | ||
|
||
func init() { | ||
clientID = os.Getenv("CLIENT_ID") | ||
if clientID == "" { | ||
log.Fatal("Set the environment variable CLIENT_ID before retrying.") | ||
} | ||
|
||
clientSecret = os.Getenv("CLIENT_SECRET") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable CLIENT_SECRET before retrying.") | ||
} | ||
|
||
myDomain = os.Getenv("MY_DOMAIN") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable MY_DOMAIN before retrying.") | ||
} | ||
} | ||
|
||
func main() { | ||
blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) | ||
cfg = blizz.AuthorizeConfig(fmt.Sprintf("http://%s:9094/oauth2", myDomain), oauth.ProfileD3, oauth.ProfileSC2, oauth.ProfileWoW) | ||
|
||
http.HandleFunc("/", homepage) | ||
http.HandleFunc("/oauth2", authorize) | ||
|
||
// We start up our Client on port 9094 | ||
log.Println("Client is running at 9094 port.") | ||
log.Fatal(http.ListenAndServe(":9094", nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/FuzzyStatic/blizzard/v1" | ||
) | ||
|
||
var ( | ||
clientID string | ||
clientSecret string | ||
blizz *blizzard.Client | ||
) | ||
|
||
func init() { | ||
clientID = os.Getenv("CLIENT_ID") | ||
if clientID == "" { | ||
log.Fatal("Set the environment variable CLIENT_ID before retrying.") | ||
} | ||
|
||
clientSecret = os.Getenv("CLIENT_SECRET") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable CLIENT_SECRET before retrying.") | ||
} | ||
} | ||
|
||
func main() { | ||
blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) | ||
|
||
err := blizz.AccessTokenRequest() | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
|
||
"github.com/FuzzyStatic/blizzard/v2" | ||
"github.com/FuzzyStatic/blizzard/v2/oauth" | ||
"golang.org/x/oauth2" | ||
) | ||
|
||
var ( | ||
clientID string | ||
clientSecret string | ||
myDomain string | ||
cfg oauth2.Config | ||
blizz *blizzard.Client | ||
) | ||
|
||
func homepage(w http.ResponseWriter, r *http.Request) { | ||
fmt.Println("Homepage Hit!") | ||
http.Redirect(w, r, cfg.AuthCodeURL("my_random_state"), http.StatusFound) | ||
} | ||
|
||
func authorize(w http.ResponseWriter, r *http.Request) { | ||
err := r.ParseForm() | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
state := r.Form.Get("state") | ||
if state != "my_random_state" { | ||
http.Error(w, "State invalid", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
code := r.Form.Get("code") | ||
if code == "" { | ||
http.Error(w, "Code not found", http.StatusBadRequest) | ||
return | ||
} | ||
|
||
token, err := cfg.Exchange(context.Background(), code) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
e := json.NewEncoder(w) | ||
e.SetIndent("", " ") | ||
err = e.Encode(*token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
validation, _, err := blizz.TokenValidation(context.Background(), token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
|
||
fmt.Printf("%+v\n", validation) | ||
|
||
userInfo, _, err := blizz.UserInfoHeader(token) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
} | ||
|
||
fmt.Printf("%+v\n", userInfo) | ||
} | ||
|
||
func init() { | ||
clientID = os.Getenv("CLIENT_ID") | ||
if clientID == "" { | ||
log.Fatal("Set the environment variable CLIENT_ID before retrying.") | ||
} | ||
|
||
clientSecret = os.Getenv("CLIENT_SECRET") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable CLIENT_SECRET before retrying.") | ||
} | ||
|
||
myDomain = os.Getenv("MY_DOMAIN") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable MY_DOMAIN before retrying.") | ||
} | ||
} | ||
|
||
func main() { | ||
blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) | ||
cfg = blizz.AuthorizeConfig(fmt.Sprintf("http://%s:9094/oauth2", myDomain), oauth.ProfileD3, oauth.ProfileSC2, oauth.ProfileWoW) | ||
|
||
http.HandleFunc("/", homepage) | ||
http.HandleFunc("/oauth2", authorize) | ||
|
||
// We start up our Client on port 9094 | ||
log.Println("Client is running at 9094 port.") | ||
log.Fatal(http.ListenAndServe(":9094", nil)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/FuzzyStatic/blizzard/v2" | ||
) | ||
|
||
var ( | ||
clientID string | ||
clientSecret string | ||
blizz *blizzard.Client | ||
) | ||
|
||
func init() { | ||
clientID = os.Getenv("CLIENT_ID") | ||
if clientID == "" { | ||
log.Fatal("Set the environment variable CLIENT_ID before retrying.") | ||
} | ||
|
||
clientSecret = os.Getenv("CLIENT_SECRET") | ||
if clientSecret == "" { | ||
log.Fatal("Set the environment variable CLIENT_SECRET before retrying.") | ||
} | ||
} | ||
|
||
func main() { | ||
blizz = blizzard.NewClient(clientID, clientSecret, blizzard.US, blizzard.EnUS) | ||
|
||
err := blizz.AccessTokenRequest(context.Background()) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
} |