{"id":21134424,"url":"https://github.com/ankitbko/python-requests-msal","last_synced_at":"2026-05-19T03:02:13.775Z","repository":{"id":77390891,"uuid":"270191763","full_name":"ankitbko/python-requests-msal","owner":"ankitbko","description":"Sample app integrating python requests library with MSAL to get AD token using Device Code Flow ","archived":false,"fork":false,"pushed_at":"2020-08-18T12:36:00.000Z","size":8,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-14T12:44:32.880Z","etag":null,"topics":["active-directory","azure","microsoft-authentication-library","msal","oauth2","python","python-requests-msal","requests"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ankitbko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-07T04:28:34.000Z","updated_at":"2020-08-18T12:36:02.000Z","dependencies_parsed_at":null,"dependency_job_id":"6ce8772a-0749-44d9-b63a-1a5142c65803","html_url":"https://github.com/ankitbko/python-requests-msal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ankitbko/python-requests-msal","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankitbko%2Fpython-requests-msal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankitbko%2Fpython-requests-msal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankitbko%2Fpython-requests-msal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankitbko%2Fpython-requests-msal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ankitbko","download_url":"https://codeload.github.com/ankitbko/python-requests-msal/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ankitbko%2Fpython-requests-msal/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268670375,"owners_count":24287973,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-04T02:00:09.867Z","response_time":79,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["active-directory","azure","microsoft-authentication-library","msal","oauth2","python","python-requests-msal","requests"],"created_at":"2024-11-20T06:29:11.049Z","updated_at":"2026-05-19T03:02:08.739Z","avatar_url":"https://github.com/ankitbko.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# python-requests-msal\nSample app integrating python requests library with MSAL to get AD token using Device Code Flow \n\n# Usage\n\nFeel free to copy and use `auth.py` and `resr_service.py` in your own project. The files depends upon following PyPI -\n- [msal](https://pypi.org/project/msal/)\n- [requests](https://pypi.org/project/requests/)\n\nInitialize `DeviceCodeFlowTokenAuth` by passing `auth_config` object to it. `auth_config` must have\n- client_id: Azure AD Application ID \n- authority: Azure AD authority\n- scope: Scope to send while requesting for token\n\nPass the initialized `DeviceCodeFlowTokenAuth` to `RestService`. `RestService` will use it to set Authorization token before sending request. \n\nIn addition to above, change *_DEFAULT_TOKEN_CACHE_DIR* in `DeviceCodeFlowTokenAuth` to any folder of your choosing where you would like the token to be chached. More detaisl below.\n\n## How does it work\n\n`DeviceCodeFlowTokenAuth` accepts configuration which contains client_id, authority and scope to get access token. It first checks if a valid access token or refresh token is present in cache. The in-memory cache is serialized and stored as a file named *token* in a folder specified by `_DEFAULT_TOKEN_CACHE_DIR` variable in home folder (default *~/.myapp*). \n\nThe code will try to read the token from the folder above and populate its *TokenCache*. If valid access token exist it will use it. Otherwise if a valid refresh token exists it will use it to get a fresh access token and save it in the cache. If neither of them are valid it will initiate **device code flow** to fetch fresh tokens. The **device code flow** will print the code generated to console.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankitbko%2Fpython-requests-msal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fankitbko%2Fpython-requests-msal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fankitbko%2Fpython-requests-msal/lists"}