From f62f4ab515756dc4928ed82c2aec75dfe03e0dab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mikl=C3=B3s=20T=C3=B3th?= <tothmiklostibor@gmail.com>
Date: Thu, 12 May 2022 17:46:19 +0200
Subject: [PATCH] Add custom RedirectURL and custom option support

---
 auth.go         | 12 +++++++-----
 example_test.go |  4 +++-
 2 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/auth.go b/auth.go
index 24670d7..fc579f9 100644
--- a/auth.go
+++ b/auth.go
@@ -19,7 +19,7 @@ type Client struct {
 // Létrehoz egy klienset. Meg kell adni az AuthSCH-n fejlesztői konzolon kapott azonosítót és kulcsot, illetve a kért scope-okat
 // A scope-oktról több infót itt találsz:
 // https://git.sch.bme.hu/kszk/authsch/-/wikis/api
-func CreateClient(ClientID, ClientSecret string, Scopes []string) Client {
+func CreateClient(ClientID, ClientSecret string, Scopes []string, RedirectURL string) Client {
 	var conf = &oauth2.Config{
 		ClientID:     ClientID,
 		ClientSecret: ClientSecret,
@@ -28,6 +28,7 @@ func CreateClient(ClientID, ClientSecret string, Scopes []string) Client {
 			TokenURL: "https://auth.sch.bme.hu/oauth2/token",
 			AuthURL:  "https://auth.sch.bme.hu/site/login",
 		},
+		RedirectURL: RedirectURL,
 	}
 
 	return Client{conf}
@@ -69,10 +70,11 @@ type AccDetails struct {
 
 // Ad egy URL-t az AuthSCH-s bejelentkező ablakhoz, ide kell irányítani a usert.
 // Az AuthSCH majd visszairányítja a usert a megadott URL-re.
-func (c *Client) GetAuthURL() string {
-	// Redirect user to consent page to ask for permission
-	// for the scopes specified above.
-	url := c.Config.AuthCodeURL("state", oauth2.AccessTypeOffline)
+func (c *Client) GetAuthURL(opts ...oauth2.AuthCodeOption) string {
+	options := []oauth2.AuthCodeOption{oauth2.AccessTypeOffline}
+	options = append(options, opts...)
+
+	url := c.Config.AuthCodeURL("state", options...)
 	return url
 
 }
diff --git a/example_test.go b/example_test.go
index a241ca0..27a27e3 100644
--- a/example_test.go
+++ b/example_test.go
@@ -22,7 +22,9 @@ var auth = CreateClient(
 		"entrants",                    // nem tudom mi
 		"admembership",
 		"bmeunitscope",
-	})
+	},
+	"",
+)
 
 var authHandler = auth.GetLoginHandler(func(details *AccDetails, w http.ResponseWriter, r *http.Request) {
 	b, e := json.MarshalIndent(details, "", "    ")
-- 
GitLab