mirror of
https://github.com/zitadel/zitadel.git
synced 2024-12-19 14:27:32 +00:00
f680dd934d
* chore: rename package errors to zerrors * rename package errors to gerrors * fix error related linting issues * fix zitadel error assertion * fix gosimple linting issues * fix deprecated linting issues * resolve gci linting issues * fix import structure --------- Co-authored-by: Elio Bischof <elio@zitadel.com>
92 lines
2.3 KiB
Go
92 lines
2.3 KiB
Go
package saml
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/zitadel/saml/pkg/provider/models"
|
|
"github.com/zitadel/saml/pkg/provider/xml/samlp"
|
|
|
|
"github.com/zitadel/zitadel/internal/api/authz"
|
|
"github.com/zitadel/zitadel/internal/domain"
|
|
"github.com/zitadel/zitadel/internal/zerrors"
|
|
)
|
|
|
|
var _ models.AuthRequestInt = &AuthRequest{}
|
|
|
|
type AuthRequest struct {
|
|
*domain.AuthRequest
|
|
}
|
|
|
|
func (a *AuthRequest) GetApplicationID() string {
|
|
return a.ApplicationID
|
|
}
|
|
|
|
func (a *AuthRequest) GetID() string {
|
|
return a.ID
|
|
}
|
|
func (a *AuthRequest) GetRelayState() string {
|
|
return a.TransferState
|
|
}
|
|
func (a *AuthRequest) GetAccessConsumerServiceURL() string {
|
|
return a.CallbackURI
|
|
}
|
|
|
|
func (a *AuthRequest) GetNameID() string {
|
|
return a.UserName
|
|
}
|
|
|
|
func (a *AuthRequest) saml() *domain.AuthRequestSAML {
|
|
return a.Request.(*domain.AuthRequestSAML)
|
|
}
|
|
func (a *AuthRequest) GetAuthRequestID() string {
|
|
return a.saml().ID
|
|
}
|
|
func (a *AuthRequest) GetBindingType() string {
|
|
return a.saml().BindingType
|
|
}
|
|
func (a *AuthRequest) GetIssuer() string {
|
|
return a.saml().Issuer
|
|
}
|
|
func (a *AuthRequest) GetIssuerName() string {
|
|
return a.saml().IssuerName
|
|
}
|
|
func (a *AuthRequest) GetDestination() string {
|
|
return a.saml().Destination
|
|
}
|
|
func (a *AuthRequest) GetCode() string {
|
|
return a.saml().Code
|
|
}
|
|
func (a *AuthRequest) GetUserID() string {
|
|
return a.UserID
|
|
}
|
|
func (a *AuthRequest) GetUserName() string {
|
|
return a.UserName
|
|
}
|
|
|
|
func AuthRequestFromBusiness(authReq *domain.AuthRequest) (_ models.AuthRequestInt, err error) {
|
|
if _, ok := authReq.Request.(*domain.AuthRequestSAML); !ok {
|
|
return nil, zerrors.ThrowInvalidArgument(nil, "SAML-Hbz7A", "auth request is not of type saml")
|
|
}
|
|
return &AuthRequest{authReq}, nil
|
|
}
|
|
|
|
func CreateAuthRequestToBusiness(ctx context.Context, authReq *samlp.AuthnRequestType, acsUrl, protocolBinding, applicationID, relayState, userAgentID string) *domain.AuthRequest {
|
|
return &domain.AuthRequest{
|
|
CreationDate: time.Now(),
|
|
AgentID: userAgentID,
|
|
ApplicationID: applicationID,
|
|
CallbackURI: acsUrl,
|
|
TransferState: relayState,
|
|
InstanceID: authz.GetInstance(ctx).InstanceID(),
|
|
Request: &domain.AuthRequestSAML{
|
|
ID: authReq.Id,
|
|
BindingType: protocolBinding,
|
|
Code: "",
|
|
Issuer: authReq.Issuer.Text,
|
|
IssuerName: authReq.Issuer.SPProvidedID,
|
|
Destination: authReq.Destination,
|
|
},
|
|
}
|
|
}
|