diff --git a/auth.go b/auth.go index 24670d7c66a6990c1e222f6391761944419289b5..fc579f9de291833b2d22ed840fd00c2266dac4a6 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 a241ca0de62e4ab7990a1470dd88effe2afb351c..27a27e398fcebdca9d5fcbc7c40af609aa9ed5bd 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, "", " ")