Updated Login Module.

- Refactor raname classes and features.
        - Clean code.
This commit is contained in:
jvelilla
2015-06-11 21:50:27 -03:00
parent 18732a9532
commit afced59b0c
15 changed files with 298 additions and 336 deletions

View File

@@ -20,12 +20,10 @@
<library name="cms_demo_module" location="modules\demo\cms_demo_module-safe.ecf" readonly="false"/> <library name="cms_demo_module" location="modules\demo\cms_demo_module-safe.ecf" readonly="false"/>
<library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/> <library name="cms_model" location="..\..\library\model\cms_model-safe.ecf" readonly="false"/>
<library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/> <library name="cms_node_module" location="..\..\modules\node\node-safe.ecf" readonly="false"/>
<!--
<library name="persistence_mysql" location="..\..\library\persistence\mysql\persistence_mysql-safe.ecf" readonly="false"/>
-->
<library name="persistence_sqlite" location="..\..\library\persistence\sqlite\persistence_sqlite-safe.ecf" readonly="false"/> <library name="persistence_sqlite" location="..\..\library\persistence\sqlite\persistence_sqlite-safe.ecf" readonly="false"/>
<library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/> <library name="wsf" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf-safe.ecf"/>
<library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/> <library name="wsf_extension" location="$ISE_LIBRARY\contrib\library\web\framework\ewf\wsf\wsf_extension-safe.ecf" readonly="false"/>
</target> </target>
<target name="demo_any" extends="common"> <target name="demo_any" extends="common">
<root class="EWF_ROC_SERVER" feature="make_and_launch"/> <root class="EWF_ROC_SERVER" feature="make_and_launch"/>

View File

@@ -135,7 +135,7 @@ feature -- CMS setup
m.enable m.enable
a_setup.register_module (m) a_setup.register_module (m)
create {LOGIN_MODULE} m.make create {CMS_AUTHENTICATION_MODULE} m.make
m.enable m.enable
a_setup.register_module (m) a_setup.register_module (m)

View File

@@ -1,10 +1,10 @@
note note
description: "Summary description for {LOGIN_CONSTANTS}." description: "Summary description for {CMS_AUTHENTICATION_CONSTANTS}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
LOGIN_CONSTANTS CMS_AUTHENTICATION_CONSTANTS
feature -- Access feature -- Access

View File

@@ -1,10 +1,10 @@
note note
description: "Summary description for {LOGIN_EMAIL_SERVICE_PARAMETERS}." description: "Summary description for {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
LOGIN_EMAIL_SERVICE_PARAMETERS CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS
inherit inherit
EMAIL_SERVICE_PARAMETERS EMAIL_SERVICE_PARAMETERS

View File

@@ -4,7 +4,7 @@
revision: "$Revision: 97328 $" revision: "$Revision: 97328 $"
class class
LOGIN_MODULE CMS_AUTHENTICATION_MODULE
inherit inherit
CMS_MODULE CMS_MODULE
@@ -63,16 +63,16 @@ feature {CMS_API} -- Module Initialization
-- <Precursor> -- <Precursor>
local local
l_user_auth_api: like user_oauth_api l_user_auth_api: like user_oauth_api
l_user_auth_storage: CMS_USER_OAUTH_STORAGE_I l_user_auth_storage: CMS_OAUTH_20_STORAGE_I
do do
Precursor (a_api) Precursor (a_api)
-- Storage initialization -- Storage initialization
if attached {CMS_STORAGE_SQL_I} a_api.storage as l_storage_sql then if attached {CMS_STORAGE_SQL_I} a_api.storage as l_storage_sql then
create {CMS_USER_OAUTH_STORAGE_SQL} l_user_auth_storage.make (l_storage_sql) create {CMS_OAUTH_20_STORAGE_SQL} l_user_auth_storage.make (l_storage_sql)
else else
-- FIXME: in case of NULL storage, should Current be disabled? -- FIXME: in case of NULL storage, should Current be disabled?
create {CMS_USER_OAUTH_STORAGE_NULL} l_user_auth_storage create {CMS_OAUTH_20_STORAGE_NULL} l_user_auth_storage
end end
-- Node API initialization -- Node API initialization
@@ -92,7 +92,6 @@ feature {CMS_API} -- Module management
install (api: CMS_API) install (api: CMS_API)
local local
sql: STRING
l_setup: CMS_SETUP l_setup: CMS_SETUP
l_params: detachable STRING_TABLE [detachable ANY] l_params: detachable STRING_TABLE [detachable ANY]
l_consumers: LIST [STRING] l_consumers: LIST [STRING]
@@ -142,7 +141,7 @@ feature {CMS_API} -- Module management
feature {CMS_API} -- Access: API feature {CMS_API} -- Access: API
user_oauth_api: detachable CMS_USER_OAUTH_API user_oauth_api: detachable CMS_OAUTH_20_API
-- <Precursor> -- <Precursor>
feature -- Filters feature -- Filters
@@ -152,7 +151,7 @@ feature -- Filters
do do
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1) create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
if attached user_oauth_api as l_user_oauth_api then if attached user_oauth_api as l_user_oauth_api then
Result.extend (create {OAUTH_FILTER}.make (a_api, l_user_oauth_api)) Result.extend (create {CMS_OAUTH_20_FILTER}.make (a_api, l_user_oauth_api))
end end
end end
@@ -183,7 +182,7 @@ feature -- Router
end end
configure_web (a_api: CMS_API; a_user_oauth_api: CMS_USER_OAUTH_API; a_router: WSF_ROUTER) configure_web (a_api: CMS_API; a_user_oauth_api: CMS_OAUTH_20_API; a_router: WSF_ROUTER)
do do
a_router.handle_with_request_methods ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get) a_router.handle_with_request_methods ("/account/roc-login", create {WSF_URI_AGENT_HANDLER}.make (agent handle_login (a_api, ?, ?)), a_router.methods_head_get)
a_router.handle_with_request_methods ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register (a_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/roc-register", create {WSF_URI_AGENT_HANDLER}.make (agent handle_register (a_api, ?, ?)), a_router.methods_get_post)
@@ -192,7 +191,7 @@ feature -- Router
a_router.handle_with_request_methods ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password (a_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/new-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_new_password (a_api, ?, ?)), a_router.methods_get_post)
a_router.handle_with_request_methods ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password (a_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/reset-password", create {WSF_URI_AGENT_HANDLER}.make (agent handle_reset_password (a_api, ?, ?)), a_router.methods_get_post)
a_router.handle_with_request_methods ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/roc-logout", create {WSF_URI_AGENT_HANDLER}.make (agent handle_logout (a_api, ?, ?)), a_router.methods_get_post)
a_router.handle_with_request_methods ("/account/login-with-oauth/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_oauth (a_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/login-with-oauth/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_login_with_oauth (a_api,a_user_oauth_api, ?, ?)), a_router.methods_get_post)
a_router.handle_with_request_methods ("/account/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_callback_oauth (a_api, a_user_oauth_api, ?, ?)), a_router.methods_get_post) a_router.handle_with_request_methods ("/account/{callback}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_callback_oauth (a_api, a_user_oauth_api, ?, ?)), a_router.methods_get_post)
end end
@@ -246,8 +245,6 @@ feature -- Hooks
end end
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
vals: CMS_VALUE_TABLE
do do
if if
a_block_id.is_case_insensitive_equal_general ("login") and then a_block_id.is_case_insensitive_equal_general ("login") and then
@@ -280,36 +277,24 @@ feature -- Hooks
handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_login (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
br: BAD_REQUEST_ERROR_CMS_RESPONSE
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.set_value ("Login", "optional_content_type") r.set_value ("Login", "optional_content_type")
r.execute r.execute
end end
handle_workaround_filter (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local
r: CMS_RESPONSE
br: BAD_REQUEST_ERROR_CMS_RESPONSE
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.execute
end
handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_logout (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
l_url: STRING l_url: STRING
l_oauth_gmail: OAUTH_LOGIN
l_cookie: WSF_COOKIE l_cookie: WSF_COOKIE
do do
if if
attached {WSF_STRING} req.cookie ({LOGIN_CONSTANTS}.oauth_session) as l_cookie_token and then attached {WSF_STRING} req.cookie ({CMS_AUTHENTICATION_CONSTANTS}.oauth_session) as l_cookie_token and then
attached {CMS_USER} current_user (req) as l_user attached {CMS_USER} current_user (req) as l_user
then then
-- Logout gmail -- Logout gmail
create l_cookie.make ({LOGIN_CONSTANTS}.oauth_session, l_cookie_token.value) create l_cookie.make ({CMS_AUTHENTICATION_CONSTANTS}.oauth_session, l_cookie_token.value)
l_cookie.set_path ("/") l_cookie.set_path ("/")
l_cookie.set_max_age (-1) l_cookie.set_max_age (-1)
res.add_cookie (l_cookie) res.add_cookie (l_cookie)
@@ -335,10 +320,9 @@ feature -- Hooks
u: CMS_USER u: CMS_USER
l_roles: LIST [CMS_USER_ROLE] l_roles: LIST [CMS_USER_ROLE]
l_exist: BOOLEAN l_exist: BOOLEAN
es: LOGIN_EMAIL_SERVICE es: CMS_AUTHENTICATON_EMAIL_SERVICE
l_link: STRING l_link: STRING
l_token: STRING l_token: STRING
l_message: STRING
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.set_value ("Register", "optional_content_type") r.set_value ("Register", "optional_content_type")
@@ -381,7 +365,7 @@ feature -- Hooks
-- Send Email -- Send Email
create es.make (create {LOGIN_EMAIL_SERVICE_PARAMETERS}.make (api)) create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
write_debug_log (generator + ".handle register: send_contact_email") write_debug_log (generator + ".handle register: send_contact_email")
es.send_contact_email (l_email.value, l_link) es.send_contact_email (l_email.value, l_link)
@@ -400,9 +384,7 @@ feature -- Hooks
local local
r: CMS_RESPONSE r: CMS_RESPONSE
l_user_api: CMS_USER_API l_user_api: CMS_USER_API
l_id: INTEGER_64
l_ir: INTERNAL_SERVER_ERROR_CMS_RESPONSE l_ir: INTERNAL_SERVER_ERROR_CMS_RESPONSE
l_link: CMS_LOCAL_LINK
do do
l_user_api := api.user_api l_user_api := api.user_api
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
@@ -433,12 +415,10 @@ feature -- Hooks
handle_reactivation (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_reactivation (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
br: BAD_REQUEST_ERROR_CMS_RESPONSE es: CMS_AUTHENTICATON_EMAIL_SERVICE
es: LOGIN_EMAIL_SERVICE
l_user_api: CMS_USER_API l_user_api: CMS_USER_API
l_token: STRING l_token: STRING
l_link: STRING l_link: STRING
l_message: STRING
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if req.is_post_request_method then if req.is_post_request_method then
@@ -459,7 +439,7 @@ feature -- Hooks
l_link.append (l_token) l_link.append (l_token)
-- Send Email -- Send Email
create es.make (create {LOGIN_EMAIL_SERVICE_PARAMETERS}.make (api)) create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
write_debug_log (generator + ".handle register: send_contact_activation_email") write_debug_log (generator + ".handle register: send_contact_activation_email")
es.send_contact_activation_email (l_email.value, l_link) es.send_contact_activation_email (l_email.value, l_link)
end end
@@ -477,12 +457,10 @@ feature -- Hooks
handle_new_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_new_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
br: BAD_REQUEST_ERROR_CMS_RESPONSE es: CMS_AUTHENTICATON_EMAIL_SERVICE
es: LOGIN_EMAIL_SERVICE
l_user_api: CMS_USER_API l_user_api: CMS_USER_API
l_token: STRING l_token: STRING
l_link: STRING l_link: STRING
l_message: STRING
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if req.is_post_request_method then if req.is_post_request_method then
@@ -497,7 +475,7 @@ feature -- Hooks
l_link.append (l_token) l_link.append (l_token)
-- Send Email -- Send Email
create es.make (create {LOGIN_EMAIL_SERVICE_PARAMETERS}.make (api)) create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
write_debug_log (generator + ".handle register: send_contact_password_email") write_debug_log (generator + ".handle register: send_contact_password_email")
es.send_contact_password_email (l_email.value, l_link) es.send_contact_password_email (l_email.value, l_link)
else else
@@ -514,11 +492,7 @@ feature -- Hooks
handle_reset_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_reset_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
br: BAD_REQUEST_ERROR_CMS_RESPONSE
es: LOGIN_EMAIL_SERVICE
l_user_api: CMS_USER_API l_user_api: CMS_USER_API
l_link: STRING
l_message: STRING
do do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api) create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
l_user_api := api.user_api l_user_api := api.user_api
@@ -605,8 +579,6 @@ feature {NONE} -- Block views
end end
get_block_view_register (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_register (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
vals: CMS_VALUE_TABLE
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -643,8 +615,6 @@ feature {NONE} -- Block views
get_block_view_reactivate (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_reactivate (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
vals: CMS_VALUE_TABLE
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -679,8 +649,6 @@ feature {NONE} -- Block views
end end
get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
vals: CMS_VALUE_TABLE
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -714,8 +682,6 @@ feature {NONE} -- Block views
end end
get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE) get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
local
vals: CMS_VALUE_TABLE
do do
if a_response.request.is_get_request_method then if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -753,14 +719,14 @@ feature {NONE} -- Block views
feature -- OAuth2 Login with google. feature -- OAuth2 Login with google.
handle_login_with_oauth (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_login_with_oauth (api: CMS_API; a_oauth_api: CMS_OAUTH_20_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
l_oauth: OAUTH_LOGIN l_oauth: CMS_OAUTH_20_WORKFLOW
do do
if if
attached {WSF_STRING} req.path_parameter ("callback") as p_consumer and then attached {WSF_STRING} req.path_parameter ("callback") as p_consumer and then
attached {CMS_OAUTH_CONSUMER} oauth_consumer_by_name (api, p_consumer.value) as l_consumer attached {CMS_OAUTH_20_CONSUMER} a_oauth_api.oauth_consumer_by_name (p_consumer.value) as l_consumer
then then
create l_oauth.make (req.server_url, l_consumer) create l_oauth.make (req.server_url, l_consumer)
if attached l_oauth.authorization_url as l_authorization_url then if attached l_oauth.authorization_url as l_authorization_url then
@@ -779,18 +745,18 @@ feature -- OAuth2 Login with google.
end end
end end
handle_callback_oauth (api: CMS_API; a_user_oauth_api: CMS_USER_OAUTH_API; req: WSF_REQUEST; res: WSF_RESPONSE) handle_callback_oauth (api: CMS_API; a_user_oauth_api: CMS_OAUTH_20_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local local
r: CMS_RESPONSE r: CMS_RESPONSE
l_auth: OAUTH_LOGIN l_auth: CMS_OAUTH_20_WORKFLOW
l_user_api: CMS_USER_API l_user_api: CMS_USER_API
l_user: CMS_USER l_user: CMS_USER
l_roles: LIST [CMS_USER_ROLE] l_roles: LIST [CMS_USER_ROLE]
l_cookie: WSF_COOKIE l_cookie: WSF_COOKIE
es: LOGIN_EMAIL_SERVICE es: CMS_AUTHENTICATON_EMAIL_SERVICE
do do
if attached {WSF_STRING} req.path_parameter ("callback") as l_callback and then if attached {WSF_STRING} req.path_parameter ("callback") as l_callback and then
attached {CMS_OAUTH_CONSUMER} oauth_consumer_by_callback (api, l_callback.value) as l_consumer and then attached {CMS_OAUTH_20_CONSUMER} a_user_oauth_api.oauth_consumer_by_callback (l_callback.value) as l_consumer and then
attached {WSF_STRING} req.query_parameter ("code") as l_code attached {WSF_STRING} req.query_parameter ("code") as l_code
then then
create l_auth.make (req.server_url, l_consumer) create l_auth.make (req.server_url, l_consumer)
@@ -809,14 +775,14 @@ feature -- OAuth2 Login with google.
then then
if attached {CMS_USER} l_user_api.user_by_email (l_email) as p_user then if attached {CMS_USER} l_user_api.user_by_email (l_email) as p_user then
-- User with email exist -- User with email exist
if attached {CMS_USER} a_user_oauth_api.user_oauth2_by_id (p_user.id, "oauth2_" + l_consumer.name) then if attached {CMS_USER} a_user_oauth_api.user_oauth2_by_id (p_user.id, l_consumer.name) then
-- Update oauth entry -- Update oauth entry
a_user_oauth_api.update_user_oauth2 (l_access_token.token, l_user_profile, p_user, "oauth2_" + l_consumer.name ) a_user_oauth_api.update_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name )
else else
-- create a oauth entry -- create a oauth entry
a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, p_user, "oauth2_" + l_consumer.name ) a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name )
end end
create l_cookie.make ({LOGIN_CONSTANTS}.oauth_session, l_access_token.token) create l_cookie.make ({CMS_AUTHENTICATION_CONSTANTS}.oauth_session, l_access_token.token)
l_cookie.set_max_age (l_access_token.expires_in) l_cookie.set_max_age (l_access_token.expires_in)
l_cookie.set_path ("/") l_cookie.set_path ("/")
res.add_cookie (l_cookie) res.add_cookie (l_cookie)
@@ -834,8 +800,8 @@ feature -- OAuth2 Login with google.
l_user_api.new_user (l_user) l_user_api.new_user (l_user)
-- Add oauth entry -- Add oauth entry
a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, l_user, "oauth_" + l_consumer.name ) a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, l_user, l_consumer.name )
create l_cookie.make ({LOGIN_CONSTANTS}.oauth_session, l_access_token.token) create l_cookie.make ({CMS_AUTHENTICATION_CONSTANTS}.oauth_session, l_access_token.token)
l_cookie.set_max_age (l_access_token.expires_in) l_cookie.set_max_age (l_access_token.expires_in)
l_cookie.set_path ("/") l_cookie.set_path ("/")
res.add_cookie (l_cookie) res.add_cookie (l_cookie)
@@ -843,7 +809,7 @@ feature -- OAuth2 Login with google.
-- Send Email -- Send Email
create es.make (create {LOGIN_EMAIL_SERVICE_PARAMETERS}.make (api)) create es.make (create {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}.make (api))
write_debug_log (generator + ".handle register: send_contact_welcome_email") write_debug_log (generator + ".handle register: send_contact_welcome_email")
es.send_contact_welcome_email (l_email, "") es.send_contact_welcome_email (l_email, "")
end end
@@ -910,119 +876,6 @@ feature {NONE} -- Implementation: date and time
Result := d.date_time Result := d.date_time
end end
feature --{NONE} -- Helper OAUTH Consumers.
oauth_consumer_by_name (a_api: CMS_API; a_name: READABLE_STRING_8): detachable CMS_OAUTH_CONSUMER
local
l_params: detachable STRING_TABLE [detachable ANY]
l_setup: CMS_SETUP
do
-- TODO workaround!!, move to the persistence layer
l_setup := a_api.setup
-- Schema
if attached {CMS_STORAGE_SQL_I} a_api.storage as l_sql_storage then
-- Todo workaround, move this to his own database layer.
create l_params.make (1)
l_params.force (a_name, "name")
l_sql_storage.sql_query ("SELECT * FROM oauth2_consumers where name =:name;", l_params)
if l_sql_storage.has_error then
a_api.logger.put_error ("Could not retrieve a consumer from the database", generating_type)
else
-- Fetch a Consumer
create Result
if attached l_sql_storage.sql_read_integer_64 (1) as l_id then
Result.set_id (l_id)
end
if attached l_sql_storage.sql_read_string_32 (2) as l_name then
Result.set_name (l_name)
end
if attached l_sql_storage.sql_read_string_32 (3) as l_api_secret then
Result.set_api_secret (l_api_secret)
end
if attached l_sql_storage.sql_read_string_32 (4) as l_api_key then
Result.set_api_key (l_api_key)
end
if attached l_sql_storage.sql_read_string_32 (5) as l_scope then
Result.set_scope (l_scope)
end
if attached l_sql_storage.sql_read_string_32 (6) as l_resource_url then
Result.set_protected_resource_url (l_resource_url)
end
if attached l_sql_storage.sql_read_string_32 (7) as l_callback_name then
Result.set_callback_name (l_callback_name)
end
if attached l_sql_storage.sql_read_string_32 (8) as l_extractor then
Result.set_extractor (l_extractor)
end
if attached l_sql_storage.sql_read_string_32 (9) as l_authorize_url then
Result.set_authorize_url (l_authorize_url)
end
if attached l_sql_storage.sql_read_string_32 (10) as l_endpoint then
Result.set_endpoint (l_endpoint)
end
end
end
end
oauth_consumer_by_callback (a_api: CMS_API; a_name: READABLE_STRING_8): detachable CMS_OAUTH_CONSUMER
local
l_params: detachable STRING_TABLE [detachable ANY]
l_setup: CMS_SETUP
do
-- TODO workaround !!! move to the persistence layer.
l_setup := a_api.setup
-- Schema
if attached {CMS_STORAGE_SQL_I} a_api.storage as l_sql_storage then
-- Todo workaround, move this to his own database layer.
create l_params.make (1)
l_params.force (a_name, "name")
l_sql_storage.sql_query ("SELECT * FROM oauth2_consumers where callback_name =:name;", l_params)
if l_sql_storage.has_error then
a_api.logger.put_error ("Could not retrieve a consumer from the database", generating_type)
else
-- Fetch a Consumer
create Result
if attached l_sql_storage.sql_read_integer_64 (1) as l_id then
Result.set_id (l_id)
end
if attached l_sql_storage.sql_read_string_32 (2) as l_name then
Result.set_name (l_name)
end
if attached l_sql_storage.sql_read_string_32 (3) as l_api_secret then
Result.set_api_secret (l_api_secret)
end
if attached l_sql_storage.sql_read_string_32 (4) as l_api_key then
Result.set_api_key (l_api_key)
end
if attached l_sql_storage.sql_read_string_32 (5) as l_scope then
Result.set_scope (l_scope)
end
if attached l_sql_storage.sql_read_string_32 (6) as l_resource_url then
Result.set_protected_resource_url (l_resource_url)
end
if attached l_sql_storage.sql_read_string_32 (7) as l_callback_name then
Result.set_callback_name (l_callback_name)
end
if attached l_sql_storage.sql_read_string_32 (8) as l_extractor then
Result.set_extractor (l_extractor)
end
if attached l_sql_storage.sql_read_string_32 (9) as l_authorize_url then
Result.set_authorize_url (l_authorize_url)
end
if attached l_sql_storage.sql_read_string_32 (10) as l_endpoint then
Result.set_endpoint (l_endpoint)
end
end
end
end
note note
copyright: "Copyright (c) 1984-2013, Eiffel Software and others" copyright: "Copyright (c) 1984-2013, Eiffel Software and others"

View File

@@ -1,10 +1,10 @@
note note
description: "Summary description for {LOGIN_EMAIL_SERVICE}." description: "Summary description for {CMS_AUTHENTICATON_EMAIL_SERVICE}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
LOGIN_EMAIL_SERVICE CMS_AUTHENTICATON_EMAIL_SERVICE
inherit inherit
EMAIL_SERVICE EMAIL_SERVICE
@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
contact_email := parameters.contact_email contact_email := parameters.contact_email
end end
parameters: LOGIN_EMAIL_SERVICE_PARAMETERS parameters: CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS
-- Associated parameters. -- Associated parameters.
feature -- Access feature -- Access

View File

@@ -0,0 +1,95 @@
note
description: "[
API to manage CMS User OAuth authentication.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_OAUTH_20_API
inherit
CMS_MODULE_API
REFACTORING_HELPER
create {CMS_AUTHENTICATION_MODULE}
make_with_storage
feature {NONE} -- Initialization
make_with_storage (a_api: CMS_API; a_oauth_storage: CMS_OAUTH_20_STORAGE_I)
-- Create an object with api `a_api' and storage `a_oauth_storage'.
do
oauth_20_storage := a_oauth_storage
make (a_api)
ensure
oauht_20_storage_set: oauth_20_storage = a_oauth_storage
end
feature {CMS_MODULE} -- Access: User oauth storage.
oauth_20_storage: CMS_OAUTH_20_STORAGE_I
-- storage interface.
feature -- Access: User Oauth20
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer: READABLE_STRING_32): detachable CMS_USER
-- Retrieve a user by id `a_uid' for the consumer `a_consumer', if aby.
do
Result := oauth_20_storage.user_oauth2_by_id (a_uid, a_consumer)
end
user_oauth2_by_token (a_token: READABLE_STRING_32; a_consumer: READABLE_STRING_32): detachable CMS_USER
-- Retrieve a user by token `a_token' for the consumer `a_consumer'.
do
Result := oauth_20_storage.user_oauth2_by_token (a_token, a_consumer)
end
user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_32 ): detachable CMS_USER
-- Retrieve a user by token `a_token' searching in all the registered consumers in the system.
do
Result := oauth_20_storage.user_oauth2_without_consumer_by_token (a_token)
end
feature -- Access: Consumers OAuth20
oauth2_consumers: LIST [STRING]
-- List of Oauth_20 consumers, if any, empty in other case.
do
Result := oauth_20_storage.oauth2_consumers
end
oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by name `a_name', if any.
do
Result := oauth_20_storage.oauth_consumer_by_name (a_name)
end
oauth_consumer_by_callback (a_callback: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by callback `a_callback', if any.
do
Result := oauth_20_storage.oauth_consumer_by_callback (a_callback)
end
feature -- Change: User OAuth20
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_32)
-- Add a new user with oauth20 using the consumer `a_consumer'.
require
has_id: a_user.has_id
do
oauth_20_storage.new_user_oauth2 (a_token, a_user_profile, a_user, a_consumer)
end
update_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)
-- Updaate user `a_user' with oauth2 for the consumer `a_consumer'.
require
has_id: a_user.has_id
do
oauth_20_storage.update_user_oauth2 (a_token, a_user_profile, a_user, a_consumer_table)
end
end

View File

@@ -5,7 +5,7 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
CMS_OAUTH_CONSUMER CMS_OAUTH_20_CONSUMER
inherit inherit

View File

@@ -4,7 +4,7 @@ note
revision: "$Revision$" revision: "$Revision$"
class class
OAUTH_LOGIN CMS_OAUTH_20_WORKFLOW
inherit inherit
@@ -15,19 +15,19 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_host: READABLE_STRING_32; a_consumer: CMS_OAUTH_CONSUMER) make (a_host: READABLE_STRING_32; a_consumer: CMS_OAUTH_20_CONSUMER)
-- Create an object with the host `a_host'. -- Create an object with the host `a_host'.
do do
initilize (a_consumer) initilize (a_consumer)
create config.make_default (api_key, api_secret) create config.make_default (a_consumer.api_key, a_consumer.api_secret)
config.set_callback (a_host + "/account/"+ a_consumer.callback_name) config.set_callback (a_host + "/account/"+ a_consumer.callback_name)
config.set_scope (scope) config.set_scope (a_consumer.scope)
--Todo create a generic OAUTH_20_GENERIC_API --Todo create a generic OAUTH_20_GENERIC_API
create oauth_api.make (a_consumer.endpoint, a_consumer.authorize_url, a_consumer.extractor) create oauth_api.make (a_consumer.endpoint, a_consumer.authorize_url, a_consumer.extractor)
api_service := oauth_api.create_service (config) api_service := oauth_api.create_service (config)
end end
initilize (a_consumer: CMS_OAUTH_CONSUMER) initilize (a_consumer: CMS_OAUTH_20_CONSUMER)
do do
--Use configuration values if any if not defaul --Use configuration values if any if not defaul
api_key := a_consumer.api_key api_key := a_consumer.api_key

View File

@@ -1,100 +0,0 @@
note
description: "[
API to manage CMS User OAuth authentication.
]"
date: "$Date$"
revision: "$Revision$"
class
CMS_USER_OAUTH_API
inherit
CMS_MODULE_API
REFACTORING_HELPER
create {LOGIN_MODULE}
make_with_storage
feature {NONE} -- Initialization
make_with_storage (a_api: CMS_API; a_user_oauth_storage: CMS_USER_OAUTH_STORAGE_I)
do
user_oauth_storage := a_user_oauth_storage
make (a_api)
end
feature {CMS_MODULE} -- Access user oauth storage.
user_oauth_storage: CMS_USER_OAUTH_STORAGE_I
feature -- Access: OAuth2 Gmail
-- user_oauth2_gmail_by_id (a_uid: like {CMS_USER}.id): detachable CMS_USER
-- do
-- Result := user_oauth_storage.user_oauth2_gmail_by_id (a_uid)
-- end
-- user_by_oauth2_gmail_token (a_token: READABLE_STRING_32): detachable CMS_USER
-- do
-- Result := user_oauth_storage.user_by_oauth2_gmail_token (a_token)
-- end
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
do
Result := user_oauth_storage.user_oauth2_by_id (a_uid, a_consumer_table)
end
user_by_oauth2_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
do
Result := user_oauth_storage.user_by_oauth2_token (a_token, a_consumer_table)
end
user_by_oauth2_global_token (a_token: READABLE_STRING_32 ): detachable CMS_USER
do
Result := user_oauth_storage.user_by_oauth2_global_token (a_token)
end
oauth2_consumers: LIST [STRING]
do
Result := user_oauth_storage.oauth2_consumers
end
feature -- Change: OAuth2 Gmail
-- new_user_oauth2_gmail (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER)
-- -- Add a new user with oauth2 gmail authentication.
-- require
-- has_id: a_user.has_id
-- do
-- user_oauth_storage.new_user_oauth2_gmail (a_token, a_user_profile, a_user)
-- end
-- update_user_oauth2_gmail (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER)
-- -- Updaate user `a_user' with oauth2 gmail authentication.
-- require
-- has_id: a_user.has_id
-- do
-- user_oauth_storage.update_user_oauth2_gmail (a_token, a_user_profile, a_user)
-- end
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)
-- Add a new user with oauth2 gmail authentication.
require
has_id: a_user.has_id
do
user_oauth_storage.new_user_oauth2 (a_token, a_user_profile, a_user, a_consumer_table)
end
update_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)
-- Updaate user `a_user' with oauth2 gmail authentication.
require
has_id: a_user.has_id
do
user_oauth_storage.update_user_oauth2 (a_token, a_user_profile, a_user, a_consumer_table)
end
end

View File

@@ -1,10 +1,10 @@
note note
description: "Summary description for {OAUTH_FILTER}." description: "Summary description for {CMS_OAUTH_20_FILTER}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
OAUTH_FILTER CMS_OAUTH_20_FILTER
inherit inherit
WSF_URI_TEMPLATE_HANDLER WSF_URI_TEMPLATE_HANDLER
@@ -20,13 +20,13 @@ create
feature {NONE} -- Initialization feature {NONE} -- Initialization
make (a_api: CMS_API; a_user_oauth_api: CMS_USER_OAUTH_API) make (a_api: CMS_API; a_user_oauth_api: CMS_OAUTH_20_API)
do do
make_handler (a_api) make_handler (a_api)
user_oauth_api := a_user_oauth_api user_oauth_api := a_user_oauth_api
end end
user_oauth_api: CMS_USER_OAUTH_API user_oauth_api: CMS_OAUTH_20_API
feature -- Basic operations feature -- Basic operations
@@ -41,9 +41,9 @@ feature -- Basic operations
-- end -- end
-- A valid user -- A valid user
if if
attached {WSF_STRING} req.cookie ({LOGIN_CONSTANTS}.oauth_session) as l_roc_auth_session_token attached {WSF_STRING} req.cookie ({CMS_AUTHENTICATION_CONSTANTS}.oauth_session) as l_roc_auth_session_token
then then
if attached {CMS_USER} user_oauth_api.user_by_oauth2_global_token (l_roc_auth_session_token.value) as l_user then if attached {CMS_USER} user_oauth_api.user_oauth2_without_consumer_by_token (l_roc_auth_session_token.value) as l_user then
set_current_user (req, l_user) set_current_user (req, l_user)
execute_next (req, res) execute_next (req, res)
else else

View File

@@ -51,18 +51,18 @@ feature -- Access
end end
end end
access_token_verb: READABLE_STRING_GENERAL access_token_verb: STRING_32
do do
Result := "POST" Result := "POST"
end end
access_token_endpoint: READABLE_STRING_GENERAL access_token_endpoint: STRING_32
-- Url that receives the access token request -- Url that receives the access token request
do do
create {STRING_32} Result.make_from_string (endpoint) create {STRING_32} Result.make_from_string (endpoint)
end end
authorization_url (config: OAUTH_CONFIG): detachable READABLE_STRING_GENERAL authorization_url (config: OAUTH_CONFIG): detachable STRING_32
-- Url where you should redirect your users to authneticate -- Url where you should redirect your users to authneticate
local local
l_result: STRING_32 l_result: STRING_32

View File

@@ -1,10 +1,12 @@
note note
description: "Summary description for {CMS_USER_OAUTH_STORAGE_I}." description: "[
API to handle OAUTH storage
]"
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
deferred class deferred class
CMS_USER_OAUTH_STORAGE_I CMS_OAUTH_20_STORAGE_I
inherit inherit
SHARED_LOGGER SHARED_LOGGER
@@ -16,27 +18,39 @@ feature -- Error Handling
deferred deferred
end end
feature -- Access feature -- Access: Users
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
-- CMS User with Oauth credential by id if any. -- Retrieve a user by id `a_uid' for the consumer `a_consumer', if aby.
deferred deferred
end end
user_by_oauth2_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
-- -- CMS User with Oauth credential by access token `a_token' if any. -- Retrieve a user by token `a_token' for the consumer `a_consumer'.
deferred deferred
end end
user_by_oauth2_global_token (a_token: READABLE_STRING_32 ): detachable CMS_USER user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_32 ): detachable CMS_USER
-- -- Retrieve a user by token `a_token' searching in all the registered consumers in the system.
deferred deferred
end end
feature -- Access: Consumers
oauth2_consumers: LIST [STRING] oauth2_consumers: LIST [STRING]
deferred deferred
end end
oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by name `a_name', if any.
deferred
end
oauth_consumer_by_callback (a_callback: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by callback `a_callback', if any.
deferred
end
feature -- Change: User Oauth2 feature -- Change: User Oauth2
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32) new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)

View File

@@ -1,15 +1,15 @@
note note
description: "Summary description for {CMS_USER_OAUTH_STORAGE_NULL}." description: "Summary description for {CMS_OAUTH_20_STORAGE_NULL}."
author: "" author: ""
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_USER_OAUTH_STORAGE_NULL CMS_OAUTH_20_STORAGE_NULL
inherit inherit
CMS_USER_OAUTH_STORAGE_I CMS_OAUTH_20_STORAGE_I
feature -- Error handler feature -- Error handler
@@ -20,27 +20,39 @@ feature -- Error handler
create Result.make create Result.make
end end
feature -- Access feature -- Access: Users
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
-- CMS User with Oauth credential by id if any. -- CMS User with Oauth credential by id if any.
do do
end end
user_by_oauth2_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
-- -- CMS User with Oauth credential by access token `a_token' if any. -- -- CMS User with Oauth credential by access token `a_token' if any.
do do
end end
user_by_oauth2_global_token (a_token: READABLE_STRING_32 ): detachable CMS_USER user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_32 ): detachable CMS_USER
do do
end end
feature -- Access: Consumers
oauth2_consumers: LIST [STRING] oauth2_consumers: LIST [STRING]
do do
create {ARRAYED_LIST[STRING]} Result.make (0) create {ARRAYED_LIST[STRING]} Result.make (0)
end end
oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by name `a_name', if any.
do
end
oauth_consumer_by_callback (a_callback: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by callback `a_callback', if any.
do
end
feature -- Change: User Oauth2 feature -- Change: User Oauth2
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32) new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)

View File

@@ -1,17 +1,17 @@
note note
description: "Summary description for {CMS_USER_OAUTH_STORAGE_SQL}." description: "Summary description for {CMS_OAUTH_20_STORAGE_SQL}."
date: "$Date$" date: "$Date$"
revision: "$Revision$" revision: "$Revision$"
class class
CMS_USER_OAUTH_STORAGE_SQL CMS_OAUTH_20_STORAGE_SQL
inherit inherit
CMS_USER_OAUTH_STORAGE_I CMS_OAUTH_20_STORAGE_I
CMS_PROXY_STORAGE_SQL CMS_PROXY_STORAGE_SQL
CMS_USER_OAUTH_STORAGE_I CMS_OAUTH_20_STORAGE_I
CMS_STORAGE_SQL_I CMS_STORAGE_SQL_I
@@ -20,29 +20,29 @@ inherit
create create
make make
feature -- Access User Outh Gmail feature -- Access User Outh
user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_32 ): detachable CMS_USER
user_by_oauth2_global_token (a_token: READABLE_STRING_32 ): detachable CMS_USER -- Retrieve a user by token `a_token' searching in all the registered consumers in the system.
local local
l_list: LIST[STRING] l_list: LIST[STRING]
do do
error_handler.reset error_handler.reset
write_information_log (generator + ".user_by_oauth2_global_token") write_information_log (generator + ".user_oauth2_without_consumer_by_token")
l_list := oauth2_consumers l_list := oauth2_consumers
from from
l_list.start l_list.start
until until
l_list.after or attached Result l_list.after or attached Result
loop loop
if attached {CMS_USER} user_by_oauth2_token (a_token, "oauth2_"+l_list.item) as l_user then if attached {CMS_USER} user_oauth2_by_token (a_token, l_list.item) as l_user then
Result := l_user Result := l_user
end end
l_list.forth l_list.forth
end end
end end
user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_id (a_uid: like {CMS_USER}.id; a_consumer: READABLE_STRING_32): detachable CMS_USER
-- <Precursor> -- <Precursor>
local local
l_parameters: STRING_TABLE [detachable ANY] l_parameters: STRING_TABLE [detachable ANY]
@@ -53,7 +53,7 @@ feature -- Access User Outh Gmail
create l_parameters.make (1) create l_parameters.make (1)
l_parameters.put (a_uid, "uid") l_parameters.put (a_uid, "uid")
create l_string.make_from_string (select_user_oauth2_template_by_id) create l_string.make_from_string (select_user_oauth2_template_by_id)
l_string.replace_substring_all ("$table_name", a_consumer_table) l_string.replace_substring_all ("$table_name", sql_table_name (a_consumer))
sql_query (l_string, l_parameters) sql_query (l_string, l_parameters)
if sql_rows_count = 1 then if sql_rows_count = 1 then
Result := fetch_user Result := fetch_user
@@ -62,7 +62,7 @@ feature -- Access User Outh Gmail
end end
end end
user_by_oauth2_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER user_oauth2_by_token (a_token: READABLE_STRING_32; a_consumer: READABLE_STRING_32): detachable CMS_USER
-- <Precursor> -- <Precursor>
local local
l_parameters: STRING_TABLE [detachable ANY] l_parameters: STRING_TABLE [detachable ANY]
@@ -73,7 +73,7 @@ feature -- Access User Outh Gmail
create l_parameters.make (1) create l_parameters.make (1)
l_parameters.put (a_token, "token") l_parameters.put (a_token, "token")
create l_string.make_from_string (select_user_by_oauth2_template_token) create l_string.make_from_string (select_user_by_oauth2_template_token)
l_string.replace_substring_all ("$table_name", a_consumer_table) l_string.replace_substring_all ("$table_name", sql_table_name (a_consumer))
sql_query (l_string, l_parameters) sql_query (l_string, l_parameters)
if sql_rows_count = 1 then if sql_rows_count = 1 then
Result := fetch_user Result := fetch_user
@@ -82,6 +82,9 @@ feature -- Access User Outh Gmail
end end
end end
feature --Access: Consumers
oauth2_consumers: LIST[STRING] oauth2_consumers: LIST[STRING]
-- Return a list of consumers, or empty -- Return a list of consumers, or empty
do do
@@ -103,9 +106,45 @@ feature -- Access User Outh Gmail
end end
end end
feature -- Change: User Oauth2 Gmail oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by name `a_name', if any.
local
l_parameters: STRING_TABLE [detachable ANY]
l_string: STRING
do
error_handler.reset
write_information_log (generator + ".oauth_consumer_by_name")
create l_parameters.make (1)
l_parameters.put (a_name, "name")
sql_query (sql_oauth_consumer_name, l_parameters)
if sql_rows_count = 1 then
Result := fetch_consumer
else
check no_more_than_one: sql_rows_count = 0 end
end
end
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32) oauth_consumer_by_callback (a_callback: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER
-- Retrieve a consumer by callback `a_callback', if any.
local
l_parameters: STRING_TABLE [detachable ANY]
l_string: STRING
do
error_handler.reset
write_information_log (generator + ".oauth_consumer_by_callback")
create l_parameters.make (1)
l_parameters.put (a_callback, "name")
sql_query (sql_oauth_consumer_callback, l_parameters)
if sql_rows_count = 1 then
Result := fetch_consumer
else
check no_more_than_one: sql_rows_count = 0 end
end
end
feature -- Change: User OAuth
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_32)
-- Add a new user with oauth2 authentication. -- Add a new user with oauth2 authentication.
-- <Precursor>. -- <Precursor>.
local local
@@ -123,12 +162,12 @@ feature -- Change: User Oauth2 Gmail
l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date") l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date")
create l_string.make_from_string (sql_insert_oauth2_template) create l_string.make_from_string (sql_insert_oauth2_template)
l_string.replace_substring_all ("$table_name", a_consumer_table) l_string.replace_substring_all ("$table_name", sql_table_name (a_consumer))
sql_change (l_string, l_parameters) sql_change (l_string, l_parameters)
sql_commit_transaction sql_commit_transaction
end end
update_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32 ) update_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_32 )
-- Update user `a_user' with oauth2 authentication. -- Update user `a_user' with oauth2 authentication.
-- <Precursor> -- <Precursor>
local local
@@ -145,11 +184,49 @@ feature -- Change: User Oauth2 Gmail
l_parameters.put (a_user_profile, "profile") l_parameters.put (a_user_profile, "profile")
create l_string.make_from_string (sql_update_oauth2_template) create l_string.make_from_string (sql_update_oauth2_template)
l_string.replace_substring_all ("$table_name", a_consumer_table) l_string.replace_substring_all ("$table_name", sql_table_name (a_consumer))
sql_change (l_string, l_parameters) sql_change (l_string, l_parameters)
sql_commit_transaction sql_commit_transaction
end end
feature {NONE} -- Implementation OAuth Consumer
fetch_consumer: detachable CMS_OAUTH_20_CONSUMER
do
if attached sql_read_integer_64 (1) as l_id then
create Result
Result.set_id (l_id)
end
if Result /= Void then
if attached sql_read_string_32 (2) as l_name then
Result.set_name (l_name)
end
if attached sql_read_string_32 (3) as l_api_secret then
Result.set_api_secret (l_api_secret)
end
if attached sql_read_string_32 (4) as l_api_key then
Result.set_api_key (l_api_key)
end
if attached sql_read_string_32 (5) as l_scope then
Result.set_scope (l_scope)
end
if attached sql_read_string_32 (6) as l_resource_url then
Result.set_protected_resource_url (l_resource_url)
end
if attached sql_read_string_32 (7) as l_callback_name then
Result.set_callback_name (l_callback_name)
end
if attached sql_read_string_32 (8) as l_extractor then
Result.set_extractor (l_extractor)
end
if attached sql_read_string_32 (9) as l_authorize_url then
Result.set_authorize_url (l_authorize_url)
end
if attached sql_read_string_32 (10) as l_endpoint then
Result.set_endpoint (l_endpoint)
end
end
end
feature {NONE} -- Implementation: User feature {NONE} -- Implementation: User
fetch_user: detachable CMS_USER fetch_user: detachable CMS_USER
@@ -191,15 +268,28 @@ feature {NONE} -- Implementation: User
feature -- {NONE} User OAuth2 feature -- {NONE} User OAuth2
sql_table_name (a_consumer: READABLE_STRING_8): STRING_8
do
Result := Sql_table_prefix.twin
Result.append (a_consumer)
end
Select_user_by_oauth2_template_token: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.access_token = :token;" Select_user_by_oauth2_template_token: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.access_token = :token;"
Select_user_oauth2_template_by_id: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.uid = :uid;" Select_user_oauth2_template_by_id: STRING = "SELECT u.* FROM users as u JOIN $table_name as og ON og.uid = u.uid and og.uid = :uid;"
Sql_insert_oauth2_template: STRING = "INSERT INTO $table_name (uid, access_token, details, created) VALUES (:uid, :token, :profile, :utc_date);" Sql_insert_oauth2_template: STRING = "INSERT INTO $table_name (uid, access_token, details, created) VALUES (:uid, :token, :profile, :utc_date);"
Sql_update_oauth2_template: STRING = "UPDATE $table_name SET access_token = :token, details = :profile WHERE uid =:uid;" Sql_update_oauth2_template: STRING = "UPDATE $table_name SET access_token = :token, details = :profile WHERE uid =:uid;"
Sql_oauth_consumers: STRING = "SELECT name FROM oauth2_consumers"; Sql_oauth_consumers: STRING = "SELECT name FROM oauth2_consumers";
Sql_table_prefix: STRING = "oauth2_"
feature -- {NONE} Consumer
Sql_oauth_consumer_callback: STRING ="SELECT * FROM oauth2_consumers where callback_name =:name;"
Sql_oauth_consumer_name: STRING ="SELECT * FROM oauth2_consumers where name =:name;"
end end