我开发了一个使用UCWA和密码令牌的应用程序。我正在阅读使用事件对应用程序进行身份验证的用户的所有消息,但令牌不会持续很长时间,并且续订使用的是浏览器,这在自动化方面非常糟糕。在Skype For Business Online上自动刷新UCWA令牌
有没有办法让一个令牌不需要通过浏览器进行更新,所以我可以让我的应用程序完全自动化?我已阅读了Github和ucwa网站上的所有文档。
这是我得到令牌的请求。
获取登入URL
DEF get_signin_url(REDIRECT_URI,CLIENT_ID,租户,资源): xframe,user_discovery_uri,资源= do_autodiscover(CONFIG [ '域'])
# Build the query parameters for the signin url
params = {
'client_id': client_id,
'redirect_uri': redirect_uri,
'response_type': 'token',
'response_mode': 'form_post',
'resource': resource
}
# The authorize URL that initiates the OAuth2 client credential flow for admin consent
authorize_url = '{0}{1}'.format(authority, '/%s/oauth2/authorize?{0}' % tenant)
# Format the sign-in url for redirection
signin_url = authorize_url.format(urlencode(params))
return signin_url
后几个步骤,得到令牌:
def get_token_from_code(client_id, tenant, auth_code, redirect_uri, resource, client_secret):
# Build the post form for the token request
post_data = {
'grant_type': 'authorization_code',
'code': auth_code,
'redirect_uri': redirect_uri,
'resource': resource,
'client_id': client_id,
'client_secret': client_secret
}
# The token issuing endpoint
token_url = '{0}{1}'.format(authority, '/{0}/oauth2/token'.format(tenant))
# Perform the post to get access token
response = requests.post(token_url, data=post_data)
try:
# try to parse the returned JSON for an access token
access_token = response.json()['id_token']
return access_token
except:
raise Exception('Error retrieving token: {0} - {1}'.format(
response.status_code, response.text))
谢谢!
它看起来像你使用python。有没有理由不利用[ADAL library for Python](https://github.com/AzureAD/azure-activedirectory-library-for-python)获取令牌而不使用broswer? – ShelbyZ
谢谢你的回答!但我的主要问题不在于Active Directory令牌,而是与UCWA令牌不同。虽然我会尝试以防万一我可以使用ADAL和Andrey Markeev的答案改进我的解决方案。 :+1: –