func (s *ThirdPartyStrategy) Authenticate(r *AuthRequest) (Result, error) {
	cred := r.Credentials
	output := NewResultOutput()
	requiredCredentials := []string{HeaderIdentity, HeaderTimestamp, HeaderAccessToken, HeaderSignature}
	if err := utils.ValidateRequiredCredentials(cred, requiredCredentials); err != nil {
		return output, MissingCredentialsError{err.Error()}
	}

	tokens, err := utils.ParseTokensWithRegex(cred[HeaderIdentity], thirdPartyUserIDPattern)
	if err != nil {
		return output, err
	}

	if len(tokens) != 1 {
		return output, InvalidCredentialError{"unable to extract required information from 'x-identity' header"}
	}

	ephPbKey := tokens[0]

	if err = checkRequestExpiration(cred["x-timestamp"], s.RequestTolerance); err != nil {
		return output, err
	}

	if err = validateRequestSignature(r, ephPbKey); err != nil {
		return output, err
	}

	tkn, err := validateAccessToken(cred[HeaderAccessToken], s.TrustedKey, ephPbKey)
	if err != nil {
		return output, err
	}

	output.AddUserID(tkn.UserID)
	return output, nil
}
// Authenticate check if the JWT is signed by a trusted third party
Authenticate check if the JWT is signed by a trusted third party
// Authenticate check if the JWT is signed by a trusted third party
func (s *ThirdPartyStrategy) Authenticate(r *AuthRequest) (Result, error) {
	cred := r.Credentials
	output := NewResultOutput()
	requiredCredentials := []string{HeaderIdentity, HeaderTimestamp, HeaderAccessToken, HeaderSignature}
	if err := utils.ValidateRequiredCredentials(cred, requiredCredentials); err != nil {
		return output, MissingCredentialsError{err.Error()}
	}
	tokens, err := utils.ParseTokensWithRegex(cred[HeaderIdentity], thirdPartyUserIDPattern)
	if err != nil {
		return output, err
	}
	if len(tokens) != 1 {
		return output, InvalidCredentialError{"unable to extract required information from 'x-identity' header"}
	}
	ephPbKey := tokens[0]
	if err = checkRequestExpiration(cred["x-timestamp"], s.RequestTolerance); err != nil {
		return output, err
	}
	if err = validateRequestSignature(r, ephPbKey); err != nil {
		return output, err
	}
	tkn, err := validateAccessToken(cred[HeaderAccessToken], s.TrustedKey, ephPbKey)
	if err != nil {
		return output, err
	}
	output.AddUserID(tkn.UserID)
	return output, nil
}
func ( s * ThirdPartyStrategy ) Authenticate ( r * AuthRequest ) ( Result , error ) { cred := r . Credentials output := NewResultOutput ( ) requiredCredentials := [ ] string { HeaderIdentity , HeaderTimestamp , HeaderAccessToken , HeaderSignature } if err := utils . ValidateRequiredCredentials ( cred , requiredCredentials ) ; err != nil { return output , MissingCredentialsError { err . Error ( ) } } tokens , err := utils . ParseTokensWithRegex ( cred [ HeaderIdentity ] , thirdPartyUserIDPattern ) if err != nil { return output , err } if len ( tokens ) != 1 { return output , InvalidCredentialError { " " } } ephPbKey := tokens [ 0 ] if err = checkRequestExpiration ( cred [ " " ] , s . RequestTolerance ) ; err != nil { return output , err } if err = validateRequestSignature ( r , ephPbKey ) ; err != nil { return output , err } tkn , err := validateAccessToken ( cred [ HeaderAccessToken ] , s . TrustedKey , ephPbKey ) if err != nil { return output , err } output . AddUserID ( tkn . UserID ) return output , nil }
Authenticate check if the JWT is signed by a trusted third party
Authenticate check if the JWT is signed by a trusted third party