lib/fhir_client/client.rb
def get_oauth2_metadata_from_conformance(strict=true)
      options = {
        authorize_url: nil,
        token_url: nil
      }
      begin
        capability_statement.rest.each do |rest|
          if strict
            rest.security.service.each do |service|
              service.coding.each do |coding|
                next unless coding.code == 'SMART-on-FHIR'
                 options.merge! get_oauth2_metadata_from_service_definition(rest)
              end
            end
          else
            options.merge! get_oauth2_metadata_from_service_definition(rest)
          end
        end
      rescue => e
        FHIR.logger.error "Failed to locate SMART-on-FHIR OAuth2 Security Extensions: #{e.message}"
      end
      options.delete_if { |_k, v| v.nil? }
      options.clear if options.keys.size != 2
      options
    end
def get_oauth2_metadata_from_conformance(strict=true)
      options = {
        authorize_url: nil,
        token_url: nil
      }
      begin
        capability_statement.rest.each do |rest|
          if strict
            rest.security.service.each do |service|
              service.coding.each do |coding|
                next unless coding.code == 'SMART-on-FHIR'
                 options.merge! get_oauth2_metadata_from_service_definition(rest)
              end
            end
          else
            options.merge! get_oauth2_metadata_from_service_definition(rest)
          end
        end
      rescue => e
        FHIR.logger.error "Failed to locate SMART-on-FHIR OAuth2 Security Extensions: #{e.message}"
      end
      options.delete_if { |_k, v| v.nil? }
      options.clear if options.keys.size != 2
      options
    end
def get_oauth2_metadata_from_conformance ( strict = true ) options = { authorize_url : nil , token_url : nil } begin capability_statement . rest . each do | rest | if strict rest . security . service . each do | service | service . coding . each do | coding | next unless coding . code == 'SMART-on-FHIR' options . merge! get_oauth2_metadata_from_service_definition ( rest ) end end else options . merge! get_oauth2_metadata_from_service_definition ( rest ) end end rescue => e FHIR . logger . error "Failed to locate SMART-on-FHIR OAuth2 Security Extensions: #{e.message}" end options . delete_if { | _k , v | v . nil? } options . clear if options . keys . size != 2 options end
Get the OAuth2 server and endpoints from the capability statement
 (the server should not require OAuth2 or other special security to access
 the capability statement).
 <rest>
   <mode value="server"/>
   <documentation value="All the functionality defined in FHIR"/>
   <security>
   <extension url="http://fhir-registry.smarthealthit.org/StructureDefinition/oauth-uris">
     <extension url="register">
       <valueUri value="https://authorize-dstu2.smarthealthit.org/register"/>
     </extension>
     <extension url="authorize">
       <valueUri value="https://authorize-dstu2.smarthealthit.org/authorize"/>
     </extension>
     <extension url="token">
       <valueUri value="https://authorize-dstu2.smarthealthit.org/token"/>
     </extension>
   </extension>
   <service>
     <coding>
       <system value="http://hl7.org/fhir/vs/restful-security-service"/>
       <code value="OAuth2"/>
     </coding>
     <text value="OAuth version 2 (see oauth.net)."/>
   </service>
   <description value="SMART on FHIR uses OAuth2 for authorization"/>
 </security>
Get the OAuth2 server and endpoints from the capability statement ( the server should not require OAuth2 or other special security to access the capability statement ) . <rest > <mode value = server / > <documentation value = All the functionality defined in FHIR / > <security > <extension url = http : // fhir - registry . smarthealthit . org / StructureDefinition / oauth - uris > <extension url = register > <valueUri value = https : // authorize - dstu2 . smarthealthit . org / register / > < / extension > <extension url = authorize > <valueUri value = https : // authorize - dstu2 . smarthealthit . org / authorize / > < / extension > <extension url = token > <valueUri value = https : // authorize - dstu2 . smarthealthit . org / token / > < / extension > < / extension > <service > <coding > <system value = http : // hl7 . org / fhir / vs / restful - security - service / > <code value = OAuth2 / > < / coding > <text value = OAuth version 2 ( see oauth . net ) . / > < / service > <description value = SMART on FHIR uses OAuth2 for authorization / > < / security >