forked from oauth2-proxy/oauth2-proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add keycloak-oidc provider based on OIDCProvider
- Loading branch information
Showing
4 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package providers | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/sessions" | ||
) | ||
|
||
const keycloakOIDCProviderName = "Keycloak OIDC" | ||
|
||
// KeycloakOIDCProvider creates a Keycloak provider based on OIDCProvider | ||
type KeycloakOIDCProvider struct { | ||
*OIDCProvider | ||
} | ||
|
||
// NewKeycloakOIDCProvider makes a KeycloakOIDCProvider using the ProviderData | ||
func NewKeycloakOIDCProvider(p *ProviderData) *KeycloakOIDCProvider { | ||
p.ProviderName = keycloakOIDCProviderName | ||
return &KeycloakOIDCProvider{ | ||
OIDCProvider: &OIDCProvider{ | ||
ProviderData: p, | ||
}, | ||
} | ||
} | ||
|
||
var _ Provider = (*KeycloakOIDCProvider)(nil) | ||
|
||
// EnrichSession is called after Redeem to allow providers to enrich session fields | ||
// such as User, Email, Groups with provider specific API calls. | ||
func (p *KeycloakOIDCProvider) EnrichSession(ctx context.Context, s *sessions.SessionState) error { | ||
err := p.OIDCProvider.EnrichSession(ctx, s) | ||
if err != nil { | ||
return err | ||
} | ||
return p.extractRoles(ctx, s) | ||
} | ||
|
||
func (p *KeycloakOIDCProvider) extractRoles(ctx context.Context, s *sessions.SessionState) error { | ||
// TODO: Implement me with Access Token Role claim extraction logic | ||
return ErrNotImplemented | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package providers | ||
|
||
import ( | ||
"net/url" | ||
|
||
. "github.com/onsi/ginkgo" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Keycloak OIDC Provider Tests", func() { | ||
Context("New Provider Init", func() { | ||
It("uses the passed ProviderData", func() { | ||
p := NewKeycloakOIDCProvider( | ||
&ProviderData{ | ||
LoginURL: &url.URL{ | ||
Scheme: "https", | ||
Host: "keycloak-oidc.com", | ||
Path: "/oauth/auth"}, | ||
RedeemURL: &url.URL{ | ||
Scheme: "https", | ||
Host: "keycloak-oidc.com", | ||
Path: "/oauth/token"}, | ||
ProfileURL: &url.URL{ | ||
Scheme: "https", | ||
Host: "keycloak-oidc.com", | ||
Path: "/api/v3/user"}, | ||
ValidateURL: &url.URL{ | ||
Scheme: "https", | ||
Host: "keycloak-oidc.com", | ||
Path: "/api/v3/user"}, | ||
Scope: "openid email profile"}) | ||
providerData := p.Data() | ||
|
||
Expect(providerData.ProviderName).To(Equal(keycloakOIDCProviderName)) | ||
Expect(providerData.LoginURL.String()).To(Equal("https://keycloak-oidc.com/oauth/auth")) | ||
Expect(providerData.RedeemURL.String()).To(Equal("https://keycloak-oidc.com/oauth/token")) | ||
Expect(providerData.ProfileURL.String()).To(Equal("https://keycloak-oidc.com/api/v3/user")) | ||
Expect(providerData.ValidateURL.String()).To(Equal("https://keycloak-oidc.com/api/v3/user")) | ||
Expect(providerData.Scope).To(Equal("openid email profile")) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters