コード例 #1
0
ファイル: client.py プロジェクト: ohmtrivedi/client-py
 def __init__(self, settings=None, state=None, save_func=lambda x:x):
     self.app_id = None
     self.server = None
     self.auth = None
     self.launch_context = None
     self._patient = None
     
     # init from state
     if state is not None:
         self.from_state(state)
     
     # init from settings dict
     elif settings is not None:
         self.app_id = settings['app_id']
         self.server = FHIRServer(base_uri=settings['api_base'])
         
         scope = scope_default
         if 'launch_token' in settings:
             scope = ' launch:'.join([scope, settings['launch_token']])
         else:
             scope = ' '.join([scope_nolaunch, scope])
         
         auth_type = settings.get('auth_type')
         redirect = settings.get('redirect_uri')
         patient_id = settings.get('patient_id')
         if patient_id:
             self.auth = FHIRAuth.create(auth_type, app_id=self.app_id, patient_id=patient_id)
         else:
             self.auth = FHIRAuth.create(auth_type, app_id=self.app_id, scope=scope, redirect_uri=redirect)
     else:
         raise Exception("Must either supply settings or a state upon client initialization")
 
     self._save_func = save_func
     self.save_state()
コード例 #2
0
    def get_capability(self, force=False):
        """ Returns the server's CapabilityStatement, retrieving it if needed
        or forced.
        """
        if self._capability is None or force:
            logger.info('Fetching CapabilityStatement from {0}'.format(
                self.base_uri))
            from models import capabilitystatement
            conf = capabilitystatement.CapabilityStatement.read_from(
                'metadata', self)
            self._capability = conf

            security = None
            try:
                security = conf.rest[0].security
            except Exception as e:
                logger.info(
                    "No REST security statement found in server capability statement"
                )

            settings = {
                'aud':
                self.base_uri,
                'app_id':
                self.client.app_id if self.client is not None else None,
                'app_secret':
                self.client.app_secret if self.client is not None else None,
                'redirect_uri':
                self.client.redirect if self.client is not None else None,
            }
            self.auth = FHIRAuth.from_capability_security(security, settings)
            self.should_save_state()
コード例 #3
0
 def from_state(self, state):
     """ Update ivars from given state information.
     """
     assert state
     self.base_uri = state.get('base_uri') or self.base_uri
     self.auth = FHIRAuth.create(state.get('auth_type'),
                                 state=state.get('auth'))
コード例 #4
0
ファイル: client.py プロジェクト: ohmtrivedi/client-py
 def from_state(self, state):
     assert state
     self.app_id = state.get('app_id') or self.app_id
     self.launch_context = state.get('launch_context') or self.launch_context
     self.server = FHIRServer(state=state.get('server'))
     self.auth = FHIRAuth.create(state.get('auth_type'), app_id=self.app_id, state=state.get('auth'))
     if self.auth is not None and self.auth.ready is not None:
         self.server.did_authorize(self.auth)
コード例 #5
0
ファイル: server.py プロジェクト: chaiery/client-py
 def get_conformance(self, force=False):
     """ Returns the server's conformance statement, retrieving it if needed
     or forced.
     """
     if self._conformance is None or force:
         logging.info('Fetching conformance statement from {0}'.format(self.base_uri))
         from models import conformance
         conf = conformance.Conformance.read_from('metadata', self)
         self._conformance = conf
         
         security = None
         try:
             security = conf.rest[0].security
         except Exception as e:
             logging.info("No REST security statement found in server conformance statement")
         
         settings = {
             'aud': self.base_uri,
             'app_id': self.client.app_id if self.client is not None else None,
             'redirect_uri': self.client.redirect if self.client is not None else None,
         }
         self.auth = FHIRAuth.from_conformance_security(security, settings)
         self.should_save_state()
コード例 #6
0
ファイル: server.py プロジェクト: chaiery/client-py
 def from_state(self, state):
     """ Update ivars from given state information.
     """
     assert state
     self.base_uri = state.get('base_uri') or self.base_uri
     self.auth = FHIRAuth.create(state.get('auth_type'), state=state.get('auth'))