Skip to content

Incorrect API_SCOPE in DjangoUI/production.env #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
TomAugspurger opened this issue May 23, 2023 · 1 comment
Open

Incorrect API_SCOPE in DjangoUI/production.env #10

TomAugspurger opened this issue May 23, 2023 · 1 comment

Comments

@TomAugspurger
Copy link

TomAugspurger commented May 23, 2023

This issue is for a: (mark with an x)

- [x] bug report -> please search issues before submitting
- [ ] feature request
- [ ] documentation issue or request
- [ ] regression (a behavior that used to work and stopped in a new release)

Minimal steps to reproduce

  • Follow the guide in the README.
  • Access localhost:8000 in the browser
Traceback (most recent call last):
  File "/home/taugspurger/src/msazure/redo/DjangoUI/venv/lib/python3.10/site-packages/django/core/handlers/exception.py", line 47, in inner
    response = get_response(request)
  File "/home/taugspurger/src/msazure/redo/DjangoUI/venv/lib/python3.10/site-packages/django/core/handlers/base.py", line 181, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/home/taugspurger/src/msazure/redo/DjangoUI/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 70, in view
    return self.dispatch(request, *args, **kwargs)
  File "/home/taugspurger/src/msazure/redo/DjangoUI/venv/lib/python3.10/site-packages/django/views/generic/base.py", line 98, in dispatch
    return handler(request, *args, **kwargs)
  File "/home/taugspurger/src/msazure/redo/DjangoUI/AzureManagement/views.py", line 28, in get
    if "error" in token_response:

Exception Type: TypeError at /
Exception Value: argument of type 'NoneType' is not iterable

Mention any other details that might be useful

I think the correct API_SCOPE is API_SCOPE="api://Flask_API_Client_ID/access_as_user" (substituting the Flask_API_Client_ID) to match the name of the scope defined by the Flask API.

@asifkazi
Copy link

asifkazi commented Sep 28, 2024

Quite a few issues trying to get this example up and running. Scope was fixed in the powershell script but not in the production.env.

Specifying Authority in the API call barfs with an error
UserWarning: We haven't decided how/if this method will accept authority parameter

had to comment it out to get example to work:

token_response = AuthenticationHelper.get_confidential_client().acquire_token_silent(
            scopes=[os.environ.get("API_SCOPE")],
            account=accounts[0],
            #authority=os.environ.get("AUTHORITY")
        )

Additionally other problems such as issuer is not correct so the jwt.decode throws an error.

ISSUER="https://login.microsoftonline.com/<TENANT_ID>/v2.0"

To

ISSUER="https://sts.windows.net/<TENANT_ID>/"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants