question about identity model #2217
-
hey, i am fresh man for kratos. i read some code about identity module. for the identity model find these model.
CredentialsTypeTable struct {
ID uuid.UUID `json:"-" db:"id"`
Name CredentialsType `json:"-" db:"name"`
} and CredentialsType reference in next model CredentialIdentifier struct {
ID uuid.UUID `db:"id"`
Identifier string `db:"identifier"`
// IdentityCredentialsID is a helper struct field for gobuffalo.pop.
IdentityCredentialsID uuid.UUID `json:"-" db:"identity_credential_id"`
// IdentityCredentialsTypeID is a helper struct field for gobuffalo.pop.
IdentityCredentialsTypeID uuid.UUID `json:"-" db:"identity_credential_type_id"`
// CreatedAt is a helper struct field for gobuffalo.pop.
CreatedAt time.Time `json:"created_at" db:"created_at"`
// UpdatedAt is a helper struct field for gobuffalo.pop.
UpdatedAt time.Time `json:"updated_at" db:"updated_at"`
NID uuid.UUID `json:"-" faker:"-" db:"nid"`
} write sql like // #nosec G201
if err := p.GetConnection(ctx).RawQuery(fmt.Sprintf(`SELECT
ic.identity_id
FROM %s ic
INNER JOIN %s ict on ic.identity_credential_type_id = ict.id
INNER JOIN %s ici on ic.id = ici.identity_credential_id
WHERE ici.identifier = ?
AND ic.nid = ?
AND ici.nid = ?
AND ict.name = ?`,
corp.ContextualizeTableName(ctx, "identity_credentials"),
corp.ContextualizeTableName(ctx, "identity_credential_types"),
corp.ContextualizeTableName(ctx, "identity_credential_identifiers"),
),
match,
nid,
nid,
ct,
).First(&find); err != nil {
if errors.Cause(err) == sql.ErrNoRows {
return nil, nil, sqlcon.HandleError(err) // herodot.ErrNotFound.WithTrace(err).WithReasonf(`No identity matching credentials identifier "%s" could be found.`, match)
}
return nil, nil, sqlcon.HandleError(err)
} i think mybe we can reduce a model element and so we can reduce a table. identity_credential_types why we need a class to descript it? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hello @JerryZhou343
|
Beta Was this translation helpful? Give feedback.
Hello @JerryZhou343
I haven't worked on Kratos code, but I think this is for describing the different credential types and is set up this way to allow for the addition of more types in the future. From the docs: