Coder Social home page Coder Social logo

Comments (7)

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024 1

@JonsSpaghetti what if we add the following lines to UserProfile model:

# Lines 96-99:
           # set custom attributes not defined in model
           for attr_name in config:
               if attr_name not in self.__dict__:
                   setattr(self, attr_name, config[attr_name])

will it cover your issue?

It will work like:

from okta.client import Client as OktaClient
import asyncio

async def main():
    client = OktaClient()

    body = {
      "profile": {
        "firstName": "John",
        "lastName": "Smith",
        "email": "[email protected]",
        "login": "[email protected]",
        "customAttr": "custom value"
      },
      "credentials": {
        "password" : { "value": "Knock*knock*neo*111" }
      }
    }

    result = await client.create_user(body)

    body = {
      "profile": {
        "firstName": "Neo",
        "lastName": "Anderson",
        "email": "[email protected]",
        "login": "[email protected]"
      },
      "credentials": {
        "password" : { "value": "Knock*knock*neo*111" }
      }
    }

    result = await client.create_user(body)

    users, resp, err = await client.list_users()
    for user in users:
        print(user.profile.first_name, user.profile.last_name)
        print(getattr(user.profile, 'customAttr', 'User has no customAttr'))
        # or using try/except:
        try:
            print(user.profile.customAttr)
        except:
            print('User has no customAttr')

asyncio.run(main())

Result should looks like:

John Smith
custom value
Neo Anderson
User has no customAttr

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024 1

@JonsSpaghetti SDK 1.2.0 released. Full example how to work with custom attributes can be found here: https://github.com/okta/okta-sdk-python#get-and-set-custom-attributes
I'm closing this issue as resolved. Please, let us know if you have any questions/suggestions/etc.

from okta-sdk-python.

bretterer avatar bretterer commented on July 22, 2024

Hi @JonsSpaghetti, Thanks for getting in touch about this. UserProfiles are a unique cases here and sometimes a difficult thing to manage. I see that you currently have a workaround so it appears that you are not currently blocked, is this the case?

I would love to hear a bit more from you on how you would want to see this officially supported in the SDK and what you think it should look like. While we wait a response, I will discuss this with our team to see what we can do and how we can update this.

from okta-sdk-python.

JonsSpaghetti avatar JonsSpaghetti commented on July 22, 2024

Correct that I am not currently blocked, not an urgent fix, and recognize that it's more complicated than just shoving something into UserProfile.

I think in my ideal scenario the UserProfile itself would just allow submission of attributes (custom or not) and would return from the API any issues with custom attributes (ex. attribute does not exist - guessing the API does this piece already).

Since the UserProfile object itself is generated from the OpenAPI spec, it might be difficult to just arbitrarily restructure the UserProfile class to be a little bit more dynamic.
In that case, having something similar to a "custom_attributes" property that can take in a hash of values and add them to the request dict seems like a reasonable thing to do. It feels similar in nature to my workaround and if there are issues, the API would theoretically be able to point to the custom attribute as the reason why. I can ask around my team too to see who else has ideas on what the optimal developer experience might be but that's my initial two cents.

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@JonsSpaghetti Could you please, provide some code samples on how do you suppose to use custom attributes and your working workaround?
For example, if I avoid SDK and use simple curl request:

curl -X POST "https://{yourOktaDomain}/api/v1/users" \
-H "Content-Type: application/json" -H "Authorization: SSWS {yourAPIToken}" \
-d '{"profile": {"firstName": "John", "lastName": "Smith", "email": "[email protected]", "login": "[email protected]", "custom_attr": "custom value"}, "credentials": {"password": {"value": "Knock*knock*neo*111"}}}'

I get the following error, i.e. API doesn't allow to pass custom attribute:

{"errorCode":"E0000001","errorSummary":"Api validation failed: newUser","errorLink":"E0000001","errorId":"oaep3MN__1BTTygxju8qNBY5w","errorCauses":[{"errorSummary":"Property name 'custom_attr' is not defined in profile"}]}

from okta-sdk-python.

JonsSpaghetti avatar JonsSpaghetti commented on July 22, 2024

@serhiibuniak-okta I believe the reason for that error is that you haven't added the user attribute to the schema for that organization/application.

Once adding one, you shouldn't get that error anymore.

As an example, per my first post, when I use the SDK, I end up having to do the following:

  create_user_req = models.CreateUserRequest(
            {"profile": user_profile, "credentials": user_creds}
        ).as_dict()
        create_user_req["profile"]["practice_ids"] = [12345, 23456]

from okta-sdk-python.

serhiibuniak-okta avatar serhiibuniak-okta commented on July 22, 2024

@JonsSpaghetti I've got your point, thanks for explanation. Let me investigate possible solutions. Feel free to add anything whatever comes to mind.

from okta-sdk-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.