Add the backchannel logout event

This commit is contained in:
Roman Perekhod
2024-06-25 10:59:00 +02:00
parent 721b32bd1e
commit eac5eaea8f
15 changed files with 194 additions and 56 deletions

View File

@@ -88,3 +88,17 @@ func (PersonalDataExtracted) Unmarshal(v []byte) (interface{}, error) {
err := json.Unmarshal(v, &e)
return e, err
}
// BackchannelLogout is emitted when the callback from the identity provider is received
type BackchannelLogout struct {
Executant *user.UserId
SessionId string
Timestamp *types.Timestamp
}
// Unmarshal to fulfill umarshaller interface
func (BackchannelLogout) Unmarshal(v []byte) (interface{}, error) {
e := BackchannelLogout{}
err := json.Unmarshal(v, &e)
return e, err
}

View File

@@ -44,20 +44,30 @@ func GetServiceUserContext(serviceUserID string, gwc gateway.GatewayAPIClient, s
// GetServiceUserContextWithContext returns an authenticated context of the given service user
func GetServiceUserContextWithContext(ctx context.Context, gwc gateway.GatewayAPIClient, serviceUserID string, serviceUserSecret string) (context.Context, error) {
token, err := GetServiceUserToken(ctx, gwc, serviceUserID, serviceUserSecret)
if err != nil {
return nil, err
}
return metadata.AppendToOutgoingContext(ctx, ctxpkg.TokenHeader, token), nil
}
// GetServiceUserToken returns a reva authentication token for the given service user
func GetServiceUserToken(ctx context.Context, gwc gateway.GatewayAPIClient, serviceUserID string, serviceUserSecret string) (string, error) {
authRes, err := gwc.Authenticate(ctx, &gateway.AuthenticateRequest{
Type: "serviceaccounts",
ClientId: serviceUserID,
ClientSecret: serviceUserSecret,
})
if err != nil {
return nil, err
return "", err
}
if err := checkStatusCode("authenticating service user", authRes.GetStatus().GetMessage(), authRes.GetStatus().GetCode()); err != nil {
return nil, err
return "", err
}
return metadata.AppendToOutgoingContext(ctx, ctxpkg.TokenHeader, authRes.Token), nil
return authRes.Token, nil
}
// GetUser gets the specified user