M

Manual Rede das Artes

Autenticação

Provedores de autenticação

Configure como os usuários fazem login na sua instalação do Mapas Culturais.

O Mapas Culturais delega a autenticação a provedores de autenticação plugáveis. Cada provedor é uma classe PHP que estende a classe abstrata AuthProvider e é responsável por identificar usuários, criar contas no primeiro login e gerenciar sessões.

Defina o provedor ativo em config/config.php, usando a chave auth.provider. Apenas um provedor pode ficar ativo por vez.

Provedores disponíveis

Fake

Apenas para desenvolvimento e testes. Exibe uma lista de usuários e um formulário simples de criação, sem depender de serviço externo.

OpauthOpenId

Provedor OpenID genérico. Funciona com qualquer servidor compatível com OpenID, incluindo instâncias auto-hospedadas do Id da Cultura.

OpauthLoginCidadao

SSO do governo federal brasileiro, como Login Cidadão e ID Cultura. Usa OAuth 2.0 com endpoints próprios.

OpauthAuthentik

Provedor moderno de OAuth 2.0 / OIDC. Adequado para organizações que usam Authentik auto-hospedado como provedor de identidade.


Fake

Class: MapasCulturais\AuthProviders\Fake

O provedor Fake ignora toda autenticação externa. Quando uma pessoa acessa a página de login, vê uma lista pesquisável de todas as contas no banco de dados e um formulário para criar novas contas na hora.

Nunca use o provedor Fake em produção. Ele permite que qualquer pessoa com acesso à página de login se autentique como qualquer usuário, incluindo administradores.

'auth.provider' => 'Fake',

Atalho de desenvolvimento: variável de ambiente FAKE_AUTH

Em ambientes de desenvolvimento baseados em Docker, você pode habilitar a autenticação fake via módulo FakeAuthentication definindo a variável FAKE_AUTH, em vez de editar arquivos de configuração.

FAKE_AUTH=true

OpauthOpenId

Class: MapasCulturais\AuthProviders\OpauthOpenId

Esse provedor usa a biblioteca Opauth com a estratégia OpenID. Ele funciona com qualquer provedor OpenID aderente ao padrão, incluindo instâncias auto-hospedadas do Id da Cultura.

Id da Cultura, o servidor OpenID auto-hospedado, é um projeto separado do ID Cultura, serviço federal gerido pelo Ministério da Cultura e baseado em Login Cidadão. Veja OpauthLoginCidadao para essa integração.

'auth.provider' => 'OpauthOpenId',
'auth.config' => [
    // Replace with your OpenID provider domain
    'login_url'  => 'https://id.example.org/openid/',
    'logout_url' => 'https://id.example.org/accounts/logout/',
    'salt'       => 'RANDOM_SECURITY_STRING_AT_LEAST_40_CHARS',
    'timeout'    => '24 hours',
],
KeyDescription
login_urlURL of the OpenID endpoint on your identity provider
logout_urlURL that ends the session on the identity provider
saltRandom string used to sign Opauth session tokens
timeoutHow long a session remains valid (e.g. '24 hours', '8 hours')

OpauthLoginCidadao

Class: MapasCulturais\AuthProviders\OpauthLoginCidadao

Login Cidadão is the Brazilian federal government's single sign-on service, also marketed as ID Cultura when used by the Ministry of Culture. Authentication uses OAuth 2.0 with dedicated token and user-info endpoints.

'auth.provider' => 'OpauthLoginCidadao',
'auth.config'   => [
    'client_id'         => 'YOUR-CLIENT-ID',
    'client_secret'     => 'YOUR-CLIENT-SECRET',
    'auth_endpoint'     => 'https://id.cultura.gov.br/oauth/v2/auth',
    'token_endpoint'    => 'https://id.cultura.gov.br/oauth/v2/token',
    'user_info_endpoint'=> 'https://id.cultura.gov.br/api/v1/person.json',
    'timeout'           => '24 hours',
    'salt'              => 'RANDOM_SECURITY_STRING_AT_LEAST_40_CHARS',
],
KeyDescription
client_idOAuth client ID issued by Login Cidadão
client_secretOAuth client secret issued by Login Cidadão
auth_endpointAuthorization URL for the OAuth flow
token_endpointToken exchange URL
user_info_endpointURL to fetch authenticated user details
timeoutSession duration
saltRandom string for token signing

Logout inside the application

Login Cidadão does not support federated logout automatically. To log a user out of the identity provider from within Mapas Culturais, add a JavaScript function to your theme's header template.

vi src/themes/YOUR_THEME/layouts/parts/header-main-nav.php

Append the following script at the end of the file, replacing YOUR_LC_DOMAIN with the hostname of your Login Cidadão instance:

<script type="text/javascript">
function logoutForce() {
    window.open('https://YOUR_LC_DOMAIN/logout', '_blank');
    alert('Logout efetuado com sucesso!');
    location.reload();
}
</script>

Find the logout anchor tag and attach the function:

<a href="<?php echo $app->createUrl('auth', 'logout'); ?>"
   onclick="return logoutForce()">Sair</a>

OpauthAuthentik

Class: MapasCulturais\AuthProviders\OpauthAuthentik

Authentik is an open-source identity provider that supports OAuth 2.0 and OIDC. Use this provider when your organization self-hosts Authentik.

'auth.provider' => 'OpauthAuthentik',
'auth.config'   => [
    'client_id'           => 'YOUR-CLIENT-ID',
    'client_secret'       => 'YOUR-CLIENT-SECRET',
    'login_url'           => 'https://authentik.example.org',
    'logout_url'          => 'https://authentik.example.org/application/o/YOUR_APP/end-session/',
    'change_password_url' => 'https://authentik.example.org/if/user/#/settings',
    'timeout'             => '24 hours',
    'salt'                => 'RANDOM_SECURITY_STRING_AT_LEAST_40_CHARS',
],
KeyDescription
client_idOAuth client ID from your Authentik application
client_secretOAuth client secret from your Authentik application
login_urlBase URL of your Authentik instance
logout_urlEnd-session URL for federated logout
change_password_urlOptional URL shown in the user panel for password changes
timeoutSession duration
saltRandom string for token signing

When change_password_url is set, Mapas Culturais displays a "Change password" button in the user account panel that redirects to the identity provider's settings page.


Session configuration

All providers share a timeout option that controls how long an authenticated session remains valid. The value is a human-readable duration string parsed by PHP's strtotime.

'auth.config' => [
    // ...
    'timeout' => '8 hours',  // or '30 minutes', '7 days', etc.
],

After the timeout elapses, the user is treated as a guest and redirected to the login page on the next request that requires authentication.

Provider capabilities often implemented in custom integrations

The legacy documentation included a dedicated guide for a richer local-auth setup (MultipleLocalAuth). Even if that exact plugin is not part of the new canonical tree, the underlying capabilities are still relevant when evaluating an auth provider strategy.

Common capabilities that may live in a custom provider, installation plugin, or theme integration include:

  • multiple sign-in methods on the same screen
  • password strength policies and recovery UX
  • CPF or local identifier login
  • reCAPTCHA on login or registration flows
  • federated login buttons for external providers
  • custom logout behavior inside the active installation theme

When documenting or debugging authentication, separate core provider behavior from installation-specific UX and policy layers. In RedeMapas, those layers often meet in the theme and surrounding configuration rather than in the provider class alone.


How the auth provider is called

The application resolves the active provider through App::getAuth(). Controllers call $controller->requireAuthentication() at the top of any action that needs a logged-in user; this redirects anonymous visitors to the login page and resumes execution after authentication.

// Retrieve the active auth provider
$auth = $app->getAuth();

// Get the currently authenticated user (returns GuestUser if not logged in)
$user = $auth->getAuthenticatedUser();

// Check whether a user is logged in
$isLoggedIn = $auth->isUserAuthenticated();

On successful login, the provider fires the auth.successful hook, which updates lastLoginTimestamp and sends any pending notifications.


Esse material é fruto do Programa de Difusão Nacional - Funarte Redes das Artes, realizado pelo Laboratório do Futuro (entidade vinculada à Universidade Federal do Ceará) no ano de 2025.

Felicilab
Mutirão
Lab do Futuro UFC
UFC
Rede das Artes Funarte
Funarte
MinC Governo Federal

On this page