Hi this is my sso token exchange code and update c...
# ask-a-descoper
a
Hi this is my sso token exchange code and update custom Attribute for the user this is my node.js code
Copy code
async ssoExchangeCodeForToken(code: string, customerId?: number): Promise<any> {
  try {
    console.log("[DescopeService] Exchanging SSO code for token:", code);
    const resp = await this.descopeClient.saml.exchange(code);
    if (!resp.ok) {
      console.error('[DescopeService] SSO Exchange Error:', resp.error);
      throw new Error(resp.error.errorMessage || 'Failed to verify SSO code');
    }
    const { sessionJwt, refreshJwt, user } = resp.data;
    // Set customerID if provided
    if (customerId && user.loginIds?.[0]) {
      try {
        const result = await this.descopeClient.management.user.updateCustomAttribute(
          user.loginIds[0], 
          'customerId', 
          customerId
        );
        console.log(`[DescopeService] Updated customerID for user ${user.loginIds[0]}:`, result);
        console.log(`[DescopeService] Set customerID: ${customerId} for user: ${user.loginIds[0]}`);
      } catch (updateError) {
        console.error('[DescopeService] Failed to update customerID:', updateError);
        // Don't fail auth flow for attribute update errors
      }
    }
    return {
      sessionJwt,
      refreshJwt,
      user,
      tenantId: user.userTenants?.[0]?.tenantId || null
    };
  } catch (error) {
    console.error('[DescopeService] Exception in ssoExchangeCodeForToken:', error);
    throw error;
  }
}
but it is not updating the customerId set as custom Attribute these are my logs
Copy code
[DescopeService] Updated customerID for user h3suqbju8jmkwoblw9rb-ilg4jxv1tyokyh-hkhkhfs-t2z3xkq4xiwqveygkolqpcwrcilt: {
  code: 200,
  ok: true,
  response: Response {
    size: 0,
    timeout: 0,
    text: [Function (anonymous)],
    json: [Function (anonymous)],
    clone: [Function (anonymous)],
    [Symbol(Body internals)]: { body: [Gunzip], disturbed: true, error: null },
    [Symbol(Response internals)]: {
      url: '<https://api.descope.com/v1/mgmt/user/update/customAttribute>',
      status: 200,
      statusText: 'OK',
      headers: [Headers],
      counter: 0
    }
  },
  data: {
    loginIds: [
      'h3suqbju8jmkwoblw9rb-ilg4jxv1tyokyh-hkhkhfs-t2z3xkq4xiwqveygkolqpcwrcilt'
    ],
    userId: 'U39l6687N1DZ5ZyCs0V9IZHhoDm2',
    name: 'Aksha Malik',
    email: '<mailto:amalik@nucompass.com|amalik@nucompass.com>',
    phone: '',
    verifiedEmail: true,
    verifiedPhone: false,
    roleNames: [],
    userTenants: [ [Object] ],
    status: 'enabled',
    externalIds: [
      'h3suqbju8jmkwoblw9rb-ilg4jxv1tyokyh-hkhkhfs-t2z3xkq4xiwqveygkolqpcwrcilt'
    ],
    picture: '<https://graph.microsoft.com/v1.0/me/photo/$value>',
    test: false,
    customAttributes: { customerId: '' },
    createdTime: 1771258131,
    TOTP: false,
    SAML: false,
    OAuth: { T2z3XKQ4XIWQveygKOlQPcWRciLt: true },
    webauthn: false,
    password: false,
    ssoAppIds: [],
    givenName: 'Aksha',
    middleName: '',
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    customAttributes: { customerId: '' },
    createdTime: 1771258131,
    TOTP: false,
    SAML: false,
    OAuth: { T2z3XKQ4XIWQveygKOlQPcWRciLt: true },
    webauthn: false,
    password: false,
    ssoAppIds: [],
    givenName: 'Aksha',
    middleName: '',
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    SAML: false,
    OAuth: { T2z3XKQ4XIWQveygKOlQPcWRciLt: true },
    webauthn: false,
    password: false,
    ssoAppIds: [],
    givenName: 'Aksha',
    middleName: '',
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    password: false,
    ssoAppIds: [],
    givenName: 'Aksha',
    middleName: '',
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    middleName: '',
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    familyName: 'Malik',
    SCIM: false,
    push: false,
    permissions: [],
    OIDC: true
    push: false,
    permissions: [],
    OIDC: true
  }
}
  }
}
}
[DescopeService] Set customerID: 754 for user: h3suqbju8jmkwoblw9rb-ilg4jxv1tyokyh-hkhkhfs-t2z3xkq4xiwqveygkolqpcwrcilt
attached screenshot from descope console as well for ref.
👀 1
a
@Aksha Malik Thanks for reaching out, Could you please confirm that the customerId attribute exists under Users --> Custom Attributes and that its type is set to Numeric? Additionally, please share a screenshot of: 1. The Custom Attributes list 2. The configuration page for the customerId attribute This will help us investigate further.
a
hi @Aditya Arakal, sure. let me share the same
i guess the issue is, here it is of type TEXT? could that be possibly the issue?
a
Yes @Aksha Malik, please set it to Numeric if you want numbers and try again
a
okay thanks, let me check
👍 1