21.4.10 Using a Procedure to Configure Authentication at Runtime
Configure authentication at runtime by specifying a procedure on the Security page.
To configure authentication at runtime by specifying a procedure:
Example 21-1 procedure my_auth_config
This example is for an application that implements multi-tenancy and supports
                different variations of Social Sign-In for the tenants. This example uses the domain
                name in the URL to fetch configuration data (for example,
                    https://cust-01.example.com,
                    https://cust-02.example.com, and so on).
                  
procedure my_auth_config (
    p_conf in out nocopy apex_authentication.t_configuration )
is
    l_host varchar2(32767) := sys.owa_util.get_cgi_env('HTTP_HOST');
begin
    for i in ( select discovery_url,
                      auth_scheme_name,
                      credential,
                      tenant_id
                 from customer_tenants
                where hostname = l_host )
    loop
        p_conf.authentication_name := i.auth_scheme_name;
        p_conf.substitutions := apex_t_varchar2 (
                                    'DISCOVERY_URL'       , i.discovery_url,
                                    'CREDENTIAL_STATIC_ID', i.credential );
        p_conf.tenant_id := i.tenant_id;
    end loop;
end my_auth_config;
                  The procedure can change three attributes of the in/out parameter
                    p_conf, all of them are optional:
                  
authentication_name- Assign the name of an authentication scheme in your application, which will be used instead of the default scheme. Note that Switch In Session must be enabled for that scheme.substitutions- Assign name/value pairs usingapex_t_varchar2. Oracle APEX substitutes each#NAME#in the authentication scheme attributes with the associated value. The built-in Social Sign-In scheme usesCREDENTIAL_STATIC_IDto use the corresponding credential store instead of the one that was configured in the scheme.tenant_id- Set this tenant id in the session (seeAPEX_SESSION.SET_TENANT_ID).
Parent topic: Establishing User Identity Through Authentication