Skip to content

[Python 3.13] Okta Identity Engine: «requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url» #485

@yermulnik

Description

@yermulnik

I've upgraded our Okta Preview tenant from Classic to OIE and am trying to re-configure gimme-aws-creds to use Device Authorization Flow instead of Classic but to no success =(

The Classic flow works w/o issues, the okta-aws-cli works too.

I ran gimme-aws-creds --profile OKTA_PREVIEW --action-configure, filled in all the details (effectively the diff with Classic flow is the force_classic = False + client_id = <oidc app client id>), but it fails with requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: … 😢

Appreciate any assistance and hints.

> gimme-aws-creds --profile OKTA_PREVIEW --action-list-roles
Traceback (most recent call last):
  File "/home/linuxbrew/.linuxbrew/bin/gimme-aws-creds", line 17, in <module>
    GimmeAWSCreds().run()
    ~~~~~~~~~~~~~~~~~~~^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 454, in run
    self._run()
    ~~~~~~~~~^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 873, in _run
    self.handle_action_list_roles()
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 972, in handle_action_list_roles
    raise errors.GimmeAWSCredsExitSuccess(result='\n'.join(map(str, self.aws_roles)))
                                                                    ^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 719, in aws_roles
    self.saml_data['SAMLResponse'],
    ^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 710, in saml_data
    self._cache['saml_data'] = saml_data = self.okta.get_saml_response(self.aws_app['links']['appLink'], self.auth_session)
                                                                       ^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 703, in aws_app
    self._cache['aws_app'] = aws_app = self._get_selected_app(self.conf_dict.get('aws_appname'), self.aws_results)
                                                                                                 ^^^^^^^^^^^^^^^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 649, in aws_results
    self.auth_session
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/main.py", line 630, in auth_session
    auth_result = self.okta.auth_session(redirect_uri=self.conf_dict.get('app_url'), open_browser=open_browser)
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/okta_identity_engine.py", line 67, in auth_session
    login_response = self._start_device_flow()
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/gimme_aws_creds/okta_identity_engine.py", line 117, in _start_device_flow
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/home/linuxbrew/.linuxbrew/Cellar/gimme-aws-creds/2.8.2_5/libexec/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 401 Client Error: Unauthorized for url: https://[…].oktapreview.com/oauth2/v1/device/authorize

Simply flipping value of force_classic to True in config magically makes it work (but through the Classic flow obviously):

> gimme-aws-creds --profile OKTA_PREVIEW --action-list-roles
Using inherited config: DEFAULT
Okta Classic login flow enabled
Okta Password for georgii.iermulnik@[…].com:
Multi-factor Authentication required.
token:software:totp( GOOGLE ) selected : georgii.iermulnik@[…].com
Enter verification code:
RoleSet(idp='arn:aws:iam::[…]:saml-provider/okta-saml-idp-okta-preview', role='arn:aws:iam::[…]:role/okta-saml-idp-okta-preview', friendly_account_name='SingleAccountName', friendly_role_name='SingleRole')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions