Exemplo n.º 1
0
    def register(self):
        """
        Register a client at the AS
        :raises: raises error when http call fails
        """
        if 'registration_endpoint' not in self.config:
            print 'Authorization server does not support Dynamic Client Registration. Please configure client ' \
                  'credentials manually '
            return

        if 'client_id' in self.config:
            raise Exception('Client is already registered')

        dcr_access_token = None

        if 'dcr_client_id' in self.config and 'dcr_client_secret' in self.config:
            # DCR endpoint requires an access token, so perform CC flow and get one
            dcr_access_token = self.get_registration_token()

        if 'template_client' in self.config:
            print 'Registering client using template_client: %s' % self.config[
                'template_client']
            data = {'software_id': self.config['template_client']}
        else:
            data = {
                'client_name': 'OpenID Connect Demo',
                'grant_types':
                ['implicit', 'authorization_code', 'refresh_token'],
                'redirect_uris': [self.config['redirect_uri']]
            }

            if self.config['debug']:
                print 'Registering client with data:\n %s' % json.dumps(data)

        register_response = self.__urlopen(
            self.config['registration_endpoint'],
            data=json.dumps(data),
            context=self.ctx,
            token=dcr_access_token)
        self.client_data = json.loads(register_response.read())

        with open(REGISTERED_CLIENT_FILENAME, 'w') as outfile:
            outfile.write(json.dumps(self.client_data))

        if self.config['debug']:
            tools.print_json(self.client_data)

        self.read_credentials_from_file()
Exemplo n.º 2
0
def start(config):
    # load the config
    global _config
    _config = config

    global _client
    _client = Client(_config)

    # load the jwk set.
    if 'jwks_uri' in _config:
        global _jwt_validator
        _jwt_validator = JwtValidator(_config)
    else:
        print 'Found no url to JWK set, will not be able to validate JWT signature.'

    # initiate the app
    _app.secret_key = generate_random_string()

    # some default values
    _debug = 'debug' in _config and _config['debug']

    if 'port' in _config:
        port = _config['port']
    else:
        port = 5443

    if _debug:
        print 'Running conf:'
        print_json(_config)

    if 'disable_https' in _config and _config['disable_https']:
        _app.run('0.0.0.0', debug=_debug, port=port)
    else:
        _app.run('0.0.0.0',
                 debug=_debug,
                 port=port,
                 ssl_context=('keys/localhost.pem', 'keys/localhost.pem'))
Exemplo n.º 3
0
    # create a session store
    _session_store = {}

    # initiate the app
    _app.secret_key = generate_random_string()

    # some default values
    if 'port' in _config:
        port = int(_config['port'])
    else:
        port = 5443

    _disable_https = 'disable_https' in _config and _config['disable_https']

    if 'base_url' not in _config:
        _config['base_url'] = 'https://localhost:%i' % port

    debug = _config['debug'] = 'debug' in _config and _config['debug']

    if debug:
        print 'Running conf:'
        print_json(_config)

    if _disable_https:
        _app.run('0.0.0.0', debug=debug, port=port)
    else:
        _app.run('0.0.0.0',
                 debug=debug,
                 port=port,
                 ssl_context=('keys/localhost.pem', 'keys/localhost.pem'))