You've already forked oauth2-proxy
mirror of
https://github.com/oauth2-proxy/oauth2-proxy.git
synced 2025-06-15 00:15:00 +02:00
Adding the IDToken to the session for the Azure Provider.
This commit is contained in:
@ -20,6 +20,7 @@ func testAzureProvider(hostname string) *AzureProvider {
|
||||
ValidateURL: &url.URL{},
|
||||
ProtectedResource: &url.URL{},
|
||||
Scope: ""})
|
||||
|
||||
if hostname != "" {
|
||||
updateURL(p.Data().LoginURL, hostname)
|
||||
updateURL(p.Data().RedeemURL, hostname)
|
||||
@ -111,8 +112,11 @@ func testAzureBackend(payload string) *httptest.Server {
|
||||
|
||||
return httptest.NewServer(http.HandlerFunc(
|
||||
func(w http.ResponseWriter, r *http.Request) {
|
||||
if r.URL.Path != path || r.URL.RawQuery != query {
|
||||
if (r.URL.Path != path || r.URL.RawQuery != query) && r.Method != "POST" {
|
||||
w.WriteHeader(404)
|
||||
} else if r.Method == "POST" && r.Body != nil {
|
||||
w.WriteHeader(200)
|
||||
w.Write([]byte(payload))
|
||||
} else if r.Header.Get("Authorization") != "Bearer imaginary_access_token" {
|
||||
w.WriteHeader(403)
|
||||
} else {
|
||||
@ -199,3 +203,15 @@ func TestAzureProviderGetEmailAddressIncorrectOtherMails(t *testing.T) {
|
||||
assert.Equal(t, "type assertion to string failed", err.Error())
|
||||
assert.Equal(t, "", email)
|
||||
}
|
||||
|
||||
func TestAzureProviderRedeemReturnsIdToken(t *testing.T) {
|
||||
b := testAzureBackend(`{ "id_token": "testtoken1234" }`)
|
||||
defer b.Close()
|
||||
|
||||
bURL, _ := url.Parse(b.URL)
|
||||
p := testAzureProvider(bURL.Host)
|
||||
p.Data().RedeemURL.Path = "/common/oauth2/token"
|
||||
s, err := p.Redeem("https://localhost", "1234")
|
||||
assert.Equal(t, nil, err)
|
||||
assert.Equal(t, "testtoken1234", s.IDToken)
|
||||
}
|
Reference in New Issue
Block a user