add response_type to code for authentik

This commit is contained in:
kekskurse 2024-09-13 10:27:57 +02:00
parent f8f90c896c
commit ec7eab2638
2 changed files with 14 additions and 3 deletions

View file

@ -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

View file

@ -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)
}