Comments (12)
@DREW1990 Thanks for your question! Our Python SDK team will follow-up on this after the holidays.
from okta-sdk-python.
@DREW1990 Could you please, provide more details? (i.e. some code, sample output, etc.)
Full example under this section https://github.com/okta/okta-sdk-python#get-and-set-custom-attributes shows how to get custom attribute. It should be accessible via {user_obj}.profile.{custom_attribute_name}.
from okta-sdk-python.
Here's an example using requests
to get an existing custom attribute (badgeNumber
) from a user:
def get_badge_number(user):
url = f'{okta_url}/api/v1/users/{user}'
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": f"SSWS {okta_token}",
}
response = requests.get(url, headers=headers)
print(response.json()['profile']['badgeNumber'])
Which returns a string of numbers.
However, when using the Okta SDK, I'm unable to retrieve the value for badgeNumber
:
async def get_badge_number(user):
user_info, response, error = await client.get_user(user)
print(user_info.profile.badgeNumber)
This results into an error: AttributeError: 'UserProfile' object has no attribute 'badgeNumber'
The example in the README shows how to assign and create a custom attributes. However, I couldn't find a way to get any existing custom attributes. Maybe I just need more guidance on how to pull the information with the SDK?
from okta-sdk-python.
@DREW1990 Thank you for detailed response.
Currently, for variables set via config we use lowerCamelCase, but for object attributes (i.e. pythonic-way) snake_case.
Could you please, try access that value in the following way:
user_info.profile.badge_number
?
I believe, that's the way how it worked previously with regular attributes, i.e. described in model, like firstName
and first_name
.
from okta-sdk-python.
Thanks for the quick response! Unfortunately that didn't work either:
async def okta_employee(user):
user_info, response, error = await client.get_user(user)
print(user_info.profile.badge_number)
AttributeError: 'UserProfile' object has no attribute 'badge_number'
from okta-sdk-python.
Hmm, could you please, show the output of print(user_info.profile)
? Maybe, some clue is inside
from okta-sdk-python.
For privacy reasons I can't show the full output. But I did extract all of the keys.
Here are the list of profile
keys that get returned when using the SDK:
city
cost_center
country_code
department
display_name
division
email
employee_number
first_name
honorific_prefix
honorific_suffix
last_name
locale
login
manager
manager_id
middle_name
mobile_phone
nick_name
organization
postal_address
preferred_language
primary_phone
profile_url
second_email
state
street_address
timezone
title
user_type
zip_code
When using the Okta API directly with requests, it will only show the attributes that are not None
. I get the following keys:
lastName
city
displayName
badgeNumber
subDepartment
title
login
employeeNumber
division
officeLocation
mobilePhoneCountryCode
company
state
department
email
hireDate
manager
costCenter
secondEmail
managerId
team
firstName
employeeType
mobilePhone
userType
Here are the custom attributes that we set in Okta:
from okta-sdk-python.
Thank you for all the details. Very interesting, looks like a bug. Let me investigate it. Are you unblocked using requests?
from okta-sdk-python.
Awesome, thanks for the help! And nope, I can use requests for now. My team is just looking forward to using the Okta SDK for our projects going forward so we have some sort of consistency in our projects.
from okta-sdk-python.
Glad to hear that! But we will be able to release new version with fix only after all holidays. Feel free to add anything to this issue you find might be useful.
from okta-sdk-python.
@DREW1990 I can't reproduce the error.
I've added attribute and it works for me:
Could you please try run the following script with your config?
from okta.client import Client as OktaClient
import asyncio
async def main():
client = OktaClient()
users, resp, err = await client.list_users()
for user in users:
try:
print(f'{user.profile.first_name} has Badge Number: {user.profile.badge_number}')
except:
print(f'{user.profile.first_name} has no Badge Number.')
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
my output:
John has Badge Number: 123
Serhii has no Badge Number.
from okta-sdk-python.
@DREW1990 I am going to close this issue as resolved, because it looks like staled and I can't reproduce the issue: it works for me with client.get_user
, client.list_users
, etc. But please reach out to us if you find that your issue still exists.
from okta-sdk-python.
Related Issues (20)
- 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
- [Sdk v3] Evaluate event systems HOT 1
- [Sdk v3] Begin v3 branch
- [Sdk v3] Diagram injectable modules HOT 1
- [Sdk v3] Modify templates to enable custom request and response processing
- [Sdk v3] Add/Modify unit tests
- [Sdk v3] Define desired usage patterns
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.