Module: MSIDP::Endpoint
- Defined in:
- lib/msidp/endpoint.rb,
lib/msidp/endpoint/version.rb
Overview
Utility methods for Microsoft identity platform endpoints.
Constant Summary collapse
- VERSION =
'0.2.0'
Instance Method Summary collapse
-
#authorize(uri, params) ⇒ Net::HTTPResponse
Call the authorize endpoint and returns the response.
-
#authorize_uri(tenant) ⇒ Object
Returns the authorize endpoint URI object.
-
#get(uri, params, headers = nil) ⇒ Net::HTTPResponse
Get with parameters from an endpoint and returns the response.
-
#post(uri, params, headers = nil) ⇒ Net::HTTPResponse
Post parameters to an endpoint and returns the response.
-
#token(uri, params, supplement = {}) ⇒ AccessToken
Call the token endpoint and returns an issued access token.
-
#token_uri(tenant) ⇒ Object
Returns the token endpoint URI object.
-
#uri(tenant, endpoint) ⇒ Object
Returns an endpoint URI object.
-
#validate_json_response(res) ⇒ Object
Validate a HTTP response supposed to have the JSON body.
Instance Method Details
#authorize(uri, params) ⇒ Net::HTTPResponse
Call the authorize endpoint and returns the response.
40 41 42 |
# File 'lib/msidp/endpoint.rb', line 40 def (uri, params) get(uri, params) end |
#authorize_uri(tenant) ⇒ Object
Returns the authorize endpoint URI object.
14 15 16 |
# File 'lib/msidp/endpoint.rb', line 14 def (tenant) uri(tenant, 'authorize') end |
#get(uri, params, headers = nil) ⇒ Net::HTTPResponse
Get with parameters from an endpoint and returns the response.
62 63 64 65 66 67 |
# File 'lib/msidp/endpoint.rb', line 62 def get(uri, params, headers = nil) req_uri = URI.parse(uri.request_uri) req_uri.query = URI.encode_www_form(params) if params req = Net::HTTP::Get.new(req_uri.to_s, headers) https_request(uri, req) end |
#post(uri, params, headers = nil) ⇒ Net::HTTPResponse
Post parameters to an endpoint and returns the response.
75 76 77 78 79 |
# File 'lib/msidp/endpoint.rb', line 75 def post(uri, params, headers = nil) req = Net::HTTP::Post.new(uri.request_uri, headers) req.form_data = params if params https_request(uri, req) end |
#token(uri, params, supplement = {}) ⇒ AccessToken
Call the token endpoint and returns an issued access token.
50 51 52 53 54 |
# File 'lib/msidp/endpoint.rb', line 50 def token(uri, params, supplement = {}) res = validate_json_response post(uri, params) suppl = params.select { |k| k.intern == :scope }.merge(supplement) AccessToken.parse(res, suppl) end |
#token_uri(tenant) ⇒ Object
Returns the token endpoint URI object.
21 22 23 |
# File 'lib/msidp/endpoint.rb', line 21 def token_uri(tenant) uri(tenant, 'token') end |
#uri(tenant, endpoint) ⇒ Object
Returns an endpoint URI object.
29 30 31 32 33 |
# File 'lib/msidp/endpoint.rb', line 29 def uri(tenant, endpoint) URI.parse( "https://login.microsoftonline.com/#{tenant}/oauth2/v2.0/#{endpoint}" ) end |
#validate_json_response(res) ⇒ Object
Validate a HTTP response supposed to have the JSON body.
82 83 84 85 86 87 |
# File 'lib/msidp/endpoint.rb', line 82 def validate_json_response(res) raise Error, res unless res.is_a? Net::HTTPSuccess raise Error, res unless res.content_type&.start_with? 'application/json' res end |