Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: saml federation #2653

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions .schema/api.openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1932,6 +1932,81 @@
]
}
},
"/self-service/saml/metadata":{
"get":{
"description": "This endpoint is for the IDP to obtain kratos metadata",
"operationId": "getSamlMetadata",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Expose metadata of the SAML Service Provider (Kratos)",
"tags": [
"public"
]
}
},
"/self-service/saml/idp":{
"get":{
"description": "This endpoint is to redirect the user to the idp auth flow",
"operationId": "getUrlIdp",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Redirect the user to the IDP flow",
"tags": [
"public"
]
}
},
"/self-service/saml/acs":{
"get":{
"description": "AssertionConsumerService : handle saml response from the IDP",
"operationId": "getSamlAcs",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Handle SAML response from the IDP",
"tags": [
"public"
]
}
},
"/self-service/login/browser": {
"get": {
"description": "This endpoint initializes a browser-based user login flow. Once initialized, the browser will be redirected to\n`selfservice.flows.login.ui_url` with the flow ID set as the query parameter `?flow=`. If a valid user session\nexists already, the browser will be redirected to `urls.default_redirect_url` unless the query parameter\n`?refresh=true` was set.\n\nThis endpoint is NOT INTENDED for API clients and only works with browsers (Chrome, Firefox, ...).\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
Expand Down
75 changes: 75 additions & 0 deletions .schema/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -2006,6 +2006,81 @@
]
}
},
"/self-service/saml/idp":{
"get":{
"description": "This endpoint is to redirect the user to the idp auth flow",
"operationId": "getUrlIdp",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Redirect the user to the IDP flow",
"tags": [
"public"
]
}
},
"/self-service/saml/metadata":{
"get":{
"description": "This endpoint is for the IDP to obtain kratos metadata",
"operationId": "getSamlMetadata",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Expose metadata of the SAML Service Provider (Kratos)",
"tags": [
"public"
]
}
},
"/self-service/saml/acs":{
"get":{
"description": "AssertionConsumerService : handle saml response from the IDP",
"operationId": "getSamlAcs",
"response": {
"302":{
"$ref": "#/components/responses/emptyResponse"
},
"500": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/genericError"
}
}
},
"description": "genericError"
}
},
"summary": "Handle SAML response from the IDP",
"tags": [
"public"
]
}
},
"/self-service/login/flows": {
"get": {
"description": "This endpoint returns a login flow's context with, for example, error details and other information.\n\nMore information can be found at [Ory Kratos User Login and User Registration Documentation](https://www.ory.sh/docs/next/kratos/self-service/flows/user-login-user-registration).",
Expand Down
20 changes: 14 additions & 6 deletions continuity/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,16 @@ type ManagementProvider interface {
type Manager interface {
Pause(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) error
Continue(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) (*Container, error)
Abort(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) error
Abort(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) error
}

type managerOptions struct {
iid uuid.UUID
ttl time.Duration
payload json.RawMessage
payloadRaw interface{}
cleanUp bool
iid uuid.UUID
ttl time.Duration
payload json.RawMessage
payloadRaw interface{}
cleanUp bool
useRelayState bool
}

type ManagerOption func(*managerOptions) error
Expand Down Expand Up @@ -83,3 +84,10 @@ func WithPayload(payload interface{}) ManagerOption {
return nil
}
}

func UseRelayState() ManagerOption {
return func(o *managerOptions) error {
o.useRelayState = true
return nil
}
}
29 changes: 21 additions & 8 deletions continuity/manager_cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http"

"github.com/gofrs/uuid"
"github.com/gorilla/sessions"
"github.com/pkg/errors"

"github.com/ory/herodot"
Expand Down Expand Up @@ -64,12 +65,12 @@ func (m *ManagerCookie) Pause(ctx context.Context, w http.ResponseWriter, r *htt
}

func (m *ManagerCookie) Continue(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) (*Container, error) {
container, err := m.container(ctx, w, r, name)
o, err := newManagerOptions(opts)
if err != nil {
return nil, err
}

o, err := newManagerOptions(opts)
container, err := m.container(ctx, w, r, name, o.useRelayState)
if err != nil {
return nil, err
}
Expand All @@ -95,9 +96,16 @@ func (m *ManagerCookie) Continue(ctx context.Context, w http.ResponseWriter, r *
return container, nil
}

func (m *ManagerCookie) sid(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) (uuid.UUID, error) {
func (m *ManagerCookie) sid(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, useRelayState bool) (uuid.UUID, error) {
var getStringFunction func(r *http.Request, s sessions.StoreExact, id string, key interface{}) (string, error)
if useRelayState {
getStringFunction = x.SessionGetStringRelayState
} else {
getStringFunction = x.SessionGetString
}

var sid uuid.UUID
if s, err := x.SessionGetString(r, m.d.ContinuityCookieManager(ctx), CookieName, name); err != nil {
if s, err := getStringFunction(r, m.d.ContinuityCookieManager(ctx), CookieName, name); err != nil {
_ = x.SessionUnsetKey(w, r, m.d.ContinuityCookieManager(ctx), CookieName, name)
return sid, errors.WithStack(ErrNotResumable.WithDebugf("%+v", err))
} else if sid = x.ParseUUID(s); sid == uuid.Nil {
Expand All @@ -108,8 +116,8 @@ func (m *ManagerCookie) sid(ctx context.Context, w http.ResponseWriter, r *http.
return sid, nil
}

func (m *ManagerCookie) container(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) (*Container, error) {
sid, err := m.sid(ctx, w, r, name)
func (m *ManagerCookie) container(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, useRelayState bool) (*Container, error) {
sid, err := m.sid(ctx, w, r, name, useRelayState)
if err != nil {
return nil, err
}
Expand All @@ -129,8 +137,13 @@ func (m *ManagerCookie) container(ctx context.Context, w http.ResponseWriter, r
return container, err
}

func (m ManagerCookie) Abort(ctx context.Context, w http.ResponseWriter, r *http.Request, name string) error {
sid, err := m.sid(ctx, w, r, name)
func (m ManagerCookie) Abort(ctx context.Context, w http.ResponseWriter, r *http.Request, name string, opts ...ManagerOption) error {
o, err := newManagerOptions(opts)
if err != nil {
return err
}

sid, err := m.sid(ctx, w, r, name, o.useRelayState)
if errors.Is(err, &ErrNotResumable) {
// We do not care about an error here
return nil
Expand Down
Loading