我试图检索访问令牌使用天青应用程序客户端id和客户端机密。最初,我尝试使用以下python代码块
import adal
context = adal.AuthenticationContext(AUTHORITY)
token = context.acquire_token_with_client_credentials(
"https://management.azure.com/",
CLIENT_ID,
CLIENT_SECRET)
这是不带任何问题地返回令牌。我也试图使用Azure来跟踪https://github.com/Azure/azure-sdk-for-ruby中的内容,但仍然无法获得任何示例。我是红宝石的初学者,能不能请一些人与我分享这方面的经验?
从这里开始在上添加到我的帖子中
嗨,非常感谢你的支持。我遵循你的代码并编写我的代码,如下所示
require 'adal'
TENANT=<TENANT ID>
CLIENT_ID= <CLIENT_ID>
CLIENT_SECRET =<CLIENT_SECRET >
AUTHORITY = "https://login.windows.net"
auth_ctx = ADAL::AuthenticationContext.new(AUTHORITY, TENANT)
client_cred = ADAL::ClientCredential.new(CLIENT_ID, CLIENT_SECRET)
result = auth_ctx.acquire_token_for_client("https://management.azure.com/", client_cred)
puts result.access_token
但是我得到了一个错误,如下所示: check_ host ':坏组件(预期的主机组件)
但是,在Python中,它对我起了作用。
下面是完整的错误跟踪。
F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:593:in `check_host': bad component(expected host component): [https://login.windows.net] (URI::InvalidComponentError)
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:634:in `host='
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:668:in `hostname='
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:187:in `initialize'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:134:in `new'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/generic.rb:134:in `build'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/2.2.0/uri/http.rb:62:in `build'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/authority.rb:95:in `token_endpoint'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/token_request.rb:228:in `oauth_request'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/token_request.rb:182:in `request_no_cache'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/token_request.rb:171:in `request'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/token_request.rb:84:in `get_for_client'
from F:/All_Ruby_On_Rails/ruby-2.2.6-x64-mingw32/lib/ruby/gems/2.2.0/gems/adal-1.0.0/lib/adal/authentication_context.rb:78:in `acquire_token_for_client'
from F:/Selenium_Workspace_HSBC/dsi/azureadallogin.rb:9:in `<main>'
在我看来,权威常数,有问题.Can,有人在这里提供一些线索吗?
发布于 2017-06-27 08:41:56
韦尔普,他是复制者\粘贴:
# Create authentication objects
token_provider = MsRestAzure::ApplicationTokenProvider.new(tenant_id, client_id, secret)
credentials = MsRest::TokenCredentials.new(token_provider)
# Create a client - a point of access to the API and set the subscription id
client = Azure::ARM::Resources::ResourceManagementClient.new(credentials)
client.subscription_id = subscription_id
发布于 2017-06-28 08:04:25
否则,您可以使用ADAL for Ruby库获得访问令牌,就像使用Python作为您发布的代码一样。
首先,通过adal
安装gem install adal
。
然后,
adal
CLIENT_SECRET
使用acquire_token_for_client
方法通过下面的代码获取访问令牌。
要求'adal‘AUTHORITY = 'login.windows.net’auth_ctx =ADAL::AuthenticationContext.new(权威,租户) client_cred = ADAL::ClientCredential.new(CLIENT_ID,CLIENT_SECRET)结果=ADAL::ClientCredential.new client_cred)adal
PASSWORD
通过下面的代码获取访问令牌。
要求'adal‘AUTHORITY = 'login.windows.net’user_cred =ADAL::UserCredential.new(用户名、密码) ctx =user_cred=ctx.acquire_token_for_user(https://management.azure.com/"、CLIENT_ID、user_cred)放入result.access_token希望能帮上忙。
https://stackoverflow.com/questions/44773632
复制相似问题