Comments (7)
@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.
@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.
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.
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.
@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.
@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.
@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)
- Duplicate log lines when creating multiple client instances
- Reading OKTA Applications does not include configuredAttributeStatements HOT 1
- 💡 ℹ️ Update on the Python SDK Refresh ℹ️ 💡 HOT 4
- Users are missing when calling list_users() HOT 1
- [Feature Request] Device Assurance API Support
- Python 3.11 not supported? HOT 1
- error: client_assertion token has an expiration too far into the future HOT 1
- `forgot_password_generate_one_time_token` not-functional in private key mode HOT 1
- POST /token in body, not in url
- Potential data loss when saving app profile fields HOT 7
- UserFactorClient.list_factors always return null for "result" HOT 4
- [CVE-2024-23342] python-jose include by default python-ecdsa HOT 7
- Standardize configuration env vars with terraform provider
- The update_user method doesn't work reliably with string arrays
- Request Timeout cannot be set via an environment variable
- Pagination in get_logs not respecting until query parameter HOT 2
- okta/api_client.py — APIClient::form_response_body — AttributeError: 'str' object has no attribute 'items'
- vulnerability in indirect import of ecdsa library HOT 2
- Bug: "Okta direct auth API grants" are not valid OAuthGrantType HOT 3
- Missing headers throws 400 Bad request when call forgot_password_generate_one_time_token method
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from okta-sdk-python.