zitadel / actions

ZITADEL Actions - Easy extensibility with custom code. Think GitHub Actions in an Identity System.
https://zitadel.com
25 stars 6 forks source link

feat: add two actions to set picture from IdP #21

Closed jobcespedes closed 8 months ago

jobcespedes commented 9 months ago

IdP picture value is stored in metadata, then in token claim only if not already set.

tafaust commented 8 months ago

@jobcespedes With these actions active (while the add_picture_claim_from_idp_metadata is not allowed to fail), I get a 400 when running my terraform script.

This is the relevant stacktrace:

Error: error while getting org by id <REDACTED>: http status not ok: 400 Bad Request {"error":"server_error","error_description":"TypeError: Cannot read property 'picture' of undefined at add_picture_claim_from_idp_metadata (\u003ceval\u003e:11:21(4))"}

To "hotfix" this issue allow this action to fail.

To "fix" this issue, apply the following patch to this PR:

--- a/add_picture_claim_from_idp_metadata.js
+++ b/add_picture_claim_from_idp_metadata.js
@@ -8,7 +8,7 @@
  */
 function add_picture_claim_from_idp_metadata(ctx, api) {
   // return if picture already set
-  if (ctx.v1.claims.picture) {
+  if (!!ctx.v1.claims && ctx.v1.claims.picture) {
       return;
   }
jobcespedes commented 8 months ago

Hi,

Can you try modifying:

if (ctx.v1.claims && ctx.v1.claims.picture) {
    return;
}

Instead of:

if (ctx.v1.claims.picture) {
    return;
}
stebenz commented 8 months ago

@jobcespedes I will merge this PR, but as @tafaust has some comments and improvements, I would suggest doing a second PR