fix: Change oath scopes & direct debugging to console.
This commit is contained in:
@ -2,7 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
@ -25,7 +24,7 @@ var config = oauth2.Config{
|
||||
ClientSecret: "XN98Q~Wrp1RfakkihA1BaTKfokOSX9fuB01unanr",
|
||||
Endpoint: microsoft.AzureADEndpoint("ceeae22e-f163-4ac9-b7c2-45972d3aed4f"),
|
||||
RedirectURL: "https://alias.spamasaurus.com/callback",
|
||||
Scopes: []string{"User.Read", "Profile"},
|
||||
Scopes: []string{"email", "openid", "profile", "user.read"},
|
||||
}
|
||||
|
||||
var sessionStore = sessions.NewCookieStore([]byte("xDDBjhYwyndZty3exGNq2ahE8wHRCR4DfdCJCSoWXAYncfWw2UQDH63QcJ9CkrGx"))
|
||||
@ -33,7 +32,8 @@ var sessionStore = sessions.NewCookieStore([]byte("xDDBjhYwyndZty3exGNq2ahE8wHRC
|
||||
func rootHandler(w http.ResponseWriter, r *http.Request) {
|
||||
session, _ := sessionStore.Get(r, "spamasaurusRex")
|
||||
if token, ok := session.Values["token"]; ok {
|
||||
w.Write([]byte(spew.Sdump(token)))
|
||||
log.Println(spew.Sdump(token))
|
||||
w.Write([]byte("Token retrieved from session"))
|
||||
} else {
|
||||
url := config.AuthCodeURL("state", oauth2.AccessTypeOffline)
|
||||
http.Redirect(w, r, url, http.StatusFound)
|
||||
@ -45,7 +45,7 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
token, err := config.Exchange(r.Context(), r.URL.Query().Get("code"))
|
||||
if err != nil {
|
||||
if retrieveErr, ok := err.(*oauth2.RetrieveError); ok {
|
||||
w.Write([]byte(retrieveErr.ErrorDescription + " (" + retrieveErr.ErrorCode + ")"))
|
||||
log.Println(retrieveErr.ErrorDescription + " (" + retrieveErr.ErrorCode + ")")
|
||||
}
|
||||
http.Error(w, "Error exchanging code for token", http.StatusInternalServerError)
|
||||
return
|
||||
@ -56,7 +56,7 @@ func callbackHandler(w http.ResponseWriter, r *http.Request) {
|
||||
session.Values["token"] = token
|
||||
session.Save(r, w)
|
||||
|
||||
fmt.Fprintln(w, "Authentication successful!")
|
||||
w.Write([]byte("Authentication successful!"))
|
||||
|
||||
url := "https://alias.spamasaurus.com"
|
||||
http.Redirect(w, r, url, http.StatusAccepted)
|
||||
|
Reference in New Issue
Block a user