Module: Legion::Extensions::Agentic::Self::Identity::Helpers::GraphToken
- Defined in:
- lib/legion/extensions/agentic/self/identity/helpers/graph_token.rb
Defined Under Namespace
Classes: GraphTokenError
Constant Summary collapse
- TOKEN_ENDPOINT =
'https://login.microsoftonline.com/%<tenant_id>s/oauth2/v2.0/token'- GRAPH_SCOPE =
'https://graph.microsoft.com/.default'
Class Method Summary collapse
Class Method Details
.fetch(tenant_id:, client_id:, client_secret:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/legion/extensions/agentic/self/identity/helpers/graph_token.rb', line 17 def fetch(tenant_id:, client_id:, client_secret:) require 'faraday' url = format(TOKEN_ENDPOINT, tenant_id: tenant_id) conn = Faraday.new(url: url) do |c| c.request :url_encoded c.response :json, content_type: /\bjson$/ end resp = conn.post('', grant_type: 'client_credentials', client_id: client_id, client_secret: client_secret, scope: GRAPH_SCOPE) raise GraphTokenError, resp.body['error_description'] unless resp.success? resp.body['access_token'] end |