Commit 9ba34d19 authored by Daniel Scholl's avatar Daniel Scholl
Browse files

Merge branch 'weisun/feature/azure_provider' into 'master'

add entitlements client for azure provider

See merge request osdu/platform/system/sdks/common-python-sdk!1
parents 98e845cd 3a2b348e
......@@ -5,3 +5,4 @@ __pycache__
**/venv/**
**/.idea/**
.vscode/
\ No newline at end of file
# Copyright © Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os
import importlib
import importlib.util
from urllib.request import Request, urlopen
from urllib.parse import urlencode
from urllib.error import HTTPError
from json import loads
def get_bearer_token():
client_id = os.environ['client_id']
client_secret = os.environ['client_secret']
tenant_id = os.environ['tenant_id']
token_endpoint = os.environ['token_endpoint']
resource = os.environ['resource']
body = {
"grant_type": "client_credentials",
"client_id": client_id,
"client_secret": client_secret,
"resource":resource
}
headers = {
"Content-Type": "application/x-www-form-urlencoded"
}
data = urlencode(body).encode("utf8")
request = Request(url=token_endpoint, data=data, headers=headers)
try:
response = urlopen(request)
response_body = response.read()
resp = loads(response_body)
token = resp["access_token"]
except HTTPError:
raise
return f'Bearer {token}'
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment