'Handles user request to access an OpenID provider'

@web.expose
def openid_auth(self, trans, **kwd):

    if (not trans.app.config.enable_openid):
        return trans.show_error_message('OpenID    authentication    is    not    enabled    in    this    instance    of    Galaxy')
    message = 'Unspecified    failure    authenticating    via    OpenID'
    openid_url = kwd.get('openid_url', '')
    openid_provider = kwd.get('openid_provider', '')
    if ((not openid_provider) or openid_url):
        openid_provider = trans.app.openid_providers.NO_PROVIDER_ID
    redirect = kwd.get('redirect', '').strip()
    auto_associate = util.string_as_bool(kwd.get('auto_associate', False))
    use_panels = util.string_as_bool(kwd.get('use_panels', False))
    action = 'login'
    consumer = trans.app.openid_manager.get_consumer(trans)
    if openid_url:
        openid_provider_obj = trans.app.openid_providers.new_provider_from_identifier(openid_url)
    else:
        openid_provider_obj = trans.app.openid_providers.get(openid_provider)
    if ((not openid_url) and (openid_provider == trans.app.openid_providers.NO_PROVIDER_ID)):
        message = 'An    OpenID    provider    was    not    specified'
    elif openid_provider_obj:
        if (not redirect):
            redirect = '    '
        process_url = (trans.request.base.rstrip('/') + url_for(controller='user', action='openid_process', redirect=redirect, openid_provider=openid_provider, auto_associate=auto_associate))
        request = None
        try:
            request = consumer.begin(openid_provider_obj.op_endpoint_url)
            if (request is None):
                message = ('No    OpenID    services    are    available    at    %s' % openid_provider_obj.op_endpoint_url)
        except Exception as e:
            message = ('Failed    to    begin    OpenID    authentication:    %s' % str(e))
        if (request is not None):
            trans.app.openid_manager.add_sreg(trans, request, required=openid_provider_obj.sreg_required, optional=openid_provider_obj.sreg_optional)
            if request.shouldSendRedirect():
                redirect_url = request.redirectURL(trans.request.base, process_url)
                trans.app.openid_manager.persist_session(trans, consumer)
                return trans.response.send_redirect(redirect_url)
            else:
                form = request.htmlMarkup(trans.request.base, process_url, form_tag_attrs={'id': 'openid_message', 'target': '_top'})
                trans.app.openid_manager.persist_session(trans, consumer)
                return form
    return trans.response.send_redirect(url_for(controller='user', action=action, redirect=redirect, use_panels=use_panels, message=message, status='error'))
