I want to Protect amy API by using OAuth 2.0 with Azure Active Directory and API Management.
I have added my API in API management and I'm following this article https://learn.microsoft.com/en-in/azure/api-management/api-management-howto-protect-backend-with-aad.
This doc uses Azure developer console as sample app client to call the API endpoints but how can I creat my own app which will generate the auth code and I can call my APIs with using that application.
I tried using sample apps however I'm new for this so I'm not sure how to move further. So can you please help me with any python or node base code for this?
Thanks
Not sure where you are stuck. If you are a beginner for OAuth 2.0 with Azure Active Directory in Python, you can first dig into the code sample: Python authentication samples for Microsoft Graph, which shows how to use the Microsoft ADAL for Python for authentication. Please pay attention to sample_adal.py file.
@APP.route('/login/authorized')
def authorized():"""Handler for the application's Redirect Uri."""code = flask.request.args['code']auth_state = flask.request.args['state']if auth_state != SESSION.auth_state:raise Exception('state returned to redirect URL does not match!')auth_context = adal.AuthenticationContext(config.AUTHORITY_URL, api_version=None)token_response = auth_context.acquire_token_with_authorization_code(code, config.REDIRECT_URI, config.RESOURCE, config.CLIENT_ID, config.CLIENT_SECRET)SESSION.headers.update({'Authorization': f"Bearer {token_response['accessToken']}",'User-Agent': 'adal-sample','Accept': 'application/json','Content-Type': 'application/json','SdkVersion': 'sample-python-adal','return-client-request-id': 'true'})return flask.redirect('/graphcall')