From ec7eab2638bb51e83aff35baf1cd4c068b701eb5 Mon Sep 17 00:00:00 2001 From: kekskurse Date: Fri, 13 Sep 2024 10:27:57 +0200 Subject: [PATCH] add response_type to code for authentik --- auth.go | 2 ++ auth_test.go | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/auth.go b/auth.go index a1cb832..dafe519 100644 --- a/auth.go +++ b/auth.go @@ -78,6 +78,8 @@ func (a Auth) GetAuthorizationURL(redirectUrl string, scope []string, state stri values.Set("state", state) } + values.Set("response_type", "code") + url.RawQuery = values.Encode() return url.String(), nil diff --git a/auth_test.go b/auth_test.go index 2b8589f..fe5237f 100644 --- a/auth_test.go +++ b/auth_test.go @@ -1,6 +1,7 @@ package kekskurseauth import ( + "fmt" "testing" "github.com/stretchr/testify/assert" @@ -41,12 +42,12 @@ func TestGetAuthorizationUrl(t *testing.T) { { name: "plain-url", config: AuthConfig{AuthorizationEndpoint: "http://localhost/something"}, - exptUrl: "http://localhost/something?client_id=abc", + exptUrl: "http://localhost/something?client_id=abc&response_type=code", }, { name: "url-with-redirect-and-state", config: AuthConfig{AuthorizationEndpoint: "http://localhost/something"}, - exptUrl: "http://localhost/something?client_id=abc&redirect_uri=https%3A%2F%2Fexample.com&state=randomStateStringWith%C3%A4and%C3%B6ok", + exptUrl: "http://localhost/something?client_id=abc&redirect_uri=https%3A%2F%2Fexample.com&response_type=code&state=randomStateStringWith%C3%A4and%C3%B6ok", redirectURL: "https://example.com", state: "randomStateStringWithäandöok", }, @@ -54,7 +55,7 @@ func TestGetAuthorizationUrl(t *testing.T) { name: "url-with-scopes", config: AuthConfig{AuthorizationEndpoint: "http://localhost/something"}, scops: []string{"some", "söäüöäüßcopes"}, - exptUrl: "http://localhost/something?client_id=abc&scope=some%2Bs%C3%B6%C3%A4%C3%BC%C3%B6%C3%A4%C3%BC%C3%9Fcopes", + exptUrl: "http://localhost/something?client_id=abc&response_type=code&scope=some%2Bs%C3%B6%C3%A4%C3%BC%C3%B6%C3%A4%C3%BC%C3%9Fcopes", }, } @@ -73,3 +74,11 @@ func TestGetAuthorizationUrl(t *testing.T) { }) } } + +func TestAuthenticLogin(t *testing.T) { + client, err := NewAuthWithConfigurationURL("http://localhost:8084/openid-configuration", "abc", "def") + assert.Nil(t, err, "should be able to create client without error") + url, err := client.GetAuthorizationURL("http://localhost/something", []string{}, "") + assert.Nil(t, err, "should be able to create url without error") + fmt.Println(url) +}