diff --git a/examples/demo/demo-safe.ecf b/examples/demo/demo-safe.ecf
index a5c8f59..0542388 100644
--- a/examples/demo/demo-safe.ecf
+++ b/examples/demo/demo-safe.ecf
@@ -20,12 +20,10 @@
-
+
diff --git a/examples/demo/src/ewf_roc_server.e b/examples/demo/src/ewf_roc_server.e
index 86a7dd4..c2acb14 100644
--- a/examples/demo/src/ewf_roc_server.e
+++ b/examples/demo/src/ewf_roc_server.e
@@ -135,7 +135,7 @@ feature -- CMS setup
m.enable
a_setup.register_module (m)
- create {LOGIN_MODULE} m.make
+ create {CMS_AUTHENTICATION_MODULE} m.make
m.enable
a_setup.register_module (m)
diff --git a/modules/login/login_constants.e b/modules/login/cms_authentication_constants.e
similarity index 55%
rename from modules/login/login_constants.e
rename to modules/login/cms_authentication_constants.e
index ffae849..6278ed8 100644
--- a/modules/login/login_constants.e
+++ b/modules/login/cms_authentication_constants.e
@@ -1,10 +1,10 @@
note
- description: "Summary description for {LOGIN_CONSTANTS}."
+ description: "Summary description for {CMS_AUTHENTICATION_CONSTANTS}."
date: "$Date$"
revision: "$Revision$"
class
- LOGIN_CONSTANTS
+ CMS_AUTHENTICATION_CONSTANTS
feature -- Access
diff --git a/modules/login/login_email_service_parameters.e b/modules/login/cms_authentication_email_service_parameters.e
similarity index 98%
rename from modules/login/login_email_service_parameters.e
rename to modules/login/cms_authentication_email_service_parameters.e
index b3e8feb..f6be1fc 100644
--- a/modules/login/login_email_service_parameters.e
+++ b/modules/login/cms_authentication_email_service_parameters.e
@@ -1,10 +1,10 @@
note
- description: "Summary description for {LOGIN_EMAIL_SERVICE_PARAMETERS}."
+ description: "Summary description for {CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS}."
date: "$Date$"
revision: "$Revision$"
class
- LOGIN_EMAIL_SERVICE_PARAMETERS
+ CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS
inherit
EMAIL_SERVICE_PARAMETERS
diff --git a/modules/login/login_module.e b/modules/login/cms_authentication_module.e
similarity index 80%
rename from modules/login/login_module.e
rename to modules/login/cms_authentication_module.e
index e649c95..ce75ca7 100644
--- a/modules/login/login_module.e
+++ b/modules/login/cms_authentication_module.e
@@ -4,7 +4,7 @@
revision: "$Revision: 97328 $"
class
- LOGIN_MODULE
+ CMS_AUTHENTICATION_MODULE
inherit
CMS_MODULE
@@ -63,16 +63,16 @@ feature {CMS_API} -- Module Initialization
--
local
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
Precursor (a_api)
-- Storage initialization
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
-- 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
-- Node API initialization
@@ -92,7 +92,6 @@ feature {CMS_API} -- Module management
install (api: CMS_API)
local
- sql: STRING
l_setup: CMS_SETUP
l_params: detachable STRING_TABLE [detachable ANY]
l_consumers: LIST [STRING]
@@ -142,7 +141,7 @@ feature {CMS_API} -- Module management
feature {CMS_API} -- Access: API
- user_oauth_api: detachable CMS_USER_OAUTH_API
+ user_oauth_api: detachable CMS_OAUTH_20_API
--
feature -- Filters
@@ -152,7 +151,7 @@ feature -- Filters
do
create {ARRAYED_LIST [WSF_FILTER]} Result.make (1)
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
@@ -183,7 +182,7 @@ feature -- Router
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
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)
@@ -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/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/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)
end
@@ -246,8 +245,6 @@ feature -- Hooks
end
get_block_view (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
- local
- vals: CMS_VALUE_TABLE
do
if
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)
local
r: CMS_RESPONSE
- br: BAD_REQUEST_ERROR_CMS_RESPONSE
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.set_value ("Login", "optional_content_type")
r.execute
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)
local
r: CMS_RESPONSE
l_url: STRING
- l_oauth_gmail: OAUTH_LOGIN
l_cookie: WSF_COOKIE
do
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
then
-- 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_max_age (-1)
res.add_cookie (l_cookie)
@@ -335,10 +320,9 @@ feature -- Hooks
u: CMS_USER
l_roles: LIST [CMS_USER_ROLE]
l_exist: BOOLEAN
- es: LOGIN_EMAIL_SERVICE
+ es: CMS_AUTHENTICATON_EMAIL_SERVICE
l_link: STRING
l_token: STRING
- l_message: STRING
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
r.set_value ("Register", "optional_content_type")
@@ -381,7 +365,7 @@ feature -- Hooks
-- 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")
es.send_contact_email (l_email.value, l_link)
@@ -400,9 +384,7 @@ feature -- Hooks
local
r: CMS_RESPONSE
l_user_api: CMS_USER_API
- l_id: INTEGER_64
l_ir: INTERNAL_SERVER_ERROR_CMS_RESPONSE
- l_link: CMS_LOCAL_LINK
do
l_user_api := api.user_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)
local
r: CMS_RESPONSE
- br: BAD_REQUEST_ERROR_CMS_RESPONSE
- es: LOGIN_EMAIL_SERVICE
+ es: CMS_AUTHENTICATON_EMAIL_SERVICE
l_user_api: CMS_USER_API
l_token: STRING
l_link: STRING
- l_message: STRING
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if req.is_post_request_method then
@@ -459,7 +439,7 @@ feature -- Hooks
l_link.append (l_token)
-- 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")
es.send_contact_activation_email (l_email.value, l_link)
end
@@ -477,12 +457,10 @@ feature -- Hooks
handle_new_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local
r: CMS_RESPONSE
- br: BAD_REQUEST_ERROR_CMS_RESPONSE
- es: LOGIN_EMAIL_SERVICE
+ es: CMS_AUTHENTICATON_EMAIL_SERVICE
l_user_api: CMS_USER_API
l_token: STRING
l_link: STRING
- l_message: STRING
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
if req.is_post_request_method then
@@ -497,7 +475,7 @@ feature -- Hooks
l_link.append (l_token)
-- 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")
es.send_contact_password_email (l_email.value, l_link)
else
@@ -514,11 +492,7 @@ feature -- Hooks
handle_reset_password (api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE)
local
r: CMS_RESPONSE
- br: BAD_REQUEST_ERROR_CMS_RESPONSE
- es: LOGIN_EMAIL_SERVICE
l_user_api: CMS_USER_API
- l_link: STRING
- l_message: STRING
do
create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, api)
l_user_api := api.user_api
@@ -605,8 +579,6 @@ feature {NONE} -- Block views
end
get_block_view_register (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
- local
- vals: CMS_VALUE_TABLE
do
if a_response.request.is_get_request_method 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)
- local
- vals: CMS_VALUE_TABLE
do
if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -679,8 +649,6 @@ feature {NONE} -- Block views
end
get_block_view_new_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
- local
- vals: CMS_VALUE_TABLE
do
if a_response.request.is_get_request_method then
if attached template_block (a_block_id, a_response) as l_tpl_block then
@@ -714,8 +682,6 @@ feature {NONE} -- Block views
end
get_block_view_reset_password (a_block_id: READABLE_STRING_8; a_response: CMS_RESPONSE)
- local
- vals: CMS_VALUE_TABLE
do
if a_response.request.is_get_request_method 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.
- 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
r: CMS_RESPONSE
- l_oauth: OAUTH_LOGIN
+ l_oauth: CMS_OAUTH_20_WORKFLOW
do
if
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
create l_oauth.make (req.server_url, l_consumer)
if attached l_oauth.authorization_url as l_authorization_url then
@@ -779,18 +745,18 @@ feature -- OAuth2 Login with google.
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
r: CMS_RESPONSE
- l_auth: OAUTH_LOGIN
+ l_auth: CMS_OAUTH_20_WORKFLOW
l_user_api: CMS_USER_API
l_user: CMS_USER
l_roles: LIST [CMS_USER_ROLE]
l_cookie: WSF_COOKIE
- es: LOGIN_EMAIL_SERVICE
+ es: CMS_AUTHENTICATON_EMAIL_SERVICE
do
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
then
create l_auth.make (req.server_url, l_consumer)
@@ -809,14 +775,14 @@ feature -- OAuth2 Login with google.
then
if attached {CMS_USER} l_user_api.user_by_email (l_email) as p_user then
-- 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
- 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
-- 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
- 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_path ("/")
res.add_cookie (l_cookie)
@@ -834,8 +800,8 @@ feature -- OAuth2 Login with google.
l_user_api.new_user (l_user)
-- Add oauth entry
- a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, l_user, "oauth_" + l_consumer.name )
- create l_cookie.make ({LOGIN_CONSTANTS}.oauth_session, l_access_token.token)
+ a_user_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, l_user, l_consumer.name )
+ 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_path ("/")
res.add_cookie (l_cookie)
@@ -843,7 +809,7 @@ feature -- OAuth2 Login with google.
-- 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")
es.send_contact_welcome_email (l_email, "")
end
@@ -910,119 +876,6 @@ feature {NONE} -- Implementation: date and time
Result := d.date_time
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
copyright: "Copyright (c) 1984-2013, Eiffel Software and others"
diff --git a/modules/login/login_email_service.e b/modules/login/cms_authenticaton_email_service.e
similarity index 92%
rename from modules/login/login_email_service.e
rename to modules/login/cms_authenticaton_email_service.e
index 9d885b4..d4a1984 100644
--- a/modules/login/login_email_service.e
+++ b/modules/login/cms_authenticaton_email_service.e
@@ -1,10 +1,10 @@
note
- description: "Summary description for {LOGIN_EMAIL_SERVICE}."
+ description: "Summary description for {CMS_AUTHENTICATON_EMAIL_SERVICE}."
date: "$Date$"
revision: "$Revision$"
class
- LOGIN_EMAIL_SERVICE
+ CMS_AUTHENTICATON_EMAIL_SERVICE
inherit
EMAIL_SERVICE
@@ -24,7 +24,7 @@ feature {NONE} -- Initialization
contact_email := parameters.contact_email
end
- parameters: LOGIN_EMAIL_SERVICE_PARAMETERS
+ parameters: CMS_AUTHENTICATION_EMAIL_SERVICE_PARAMETERS
-- Associated parameters.
feature -- Access
diff --git a/modules/login/cms_oauth_20_api.e b/modules/login/cms_oauth_20_api.e
new file mode 100644
index 0000000..27739b2
--- /dev/null
+++ b/modules/login/cms_oauth_20_api.e
@@ -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
diff --git a/modules/login/cms_oauth_consumer.e b/modules/login/cms_oauth_20_consumer.e
similarity index 99%
rename from modules/login/cms_oauth_consumer.e
rename to modules/login/cms_oauth_20_consumer.e
index fda8210..79f3421 100644
--- a/modules/login/cms_oauth_consumer.e
+++ b/modules/login/cms_oauth_20_consumer.e
@@ -5,7 +5,7 @@ note
revision: "$Revision$"
class
- CMS_OAUTH_CONSUMER
+ CMS_OAUTH_20_CONSUMER
inherit
diff --git a/modules/login/oauth_login.e b/modules/login/cms_oauth_20_workflow.e
similarity index 93%
rename from modules/login/oauth_login.e
rename to modules/login/cms_oauth_20_workflow.e
index 6c100da..527fc6c 100644
--- a/modules/login/oauth_login.e
+++ b/modules/login/cms_oauth_20_workflow.e
@@ -4,7 +4,7 @@ note
revision: "$Revision$"
class
- OAUTH_LOGIN
+ CMS_OAUTH_20_WORKFLOW
inherit
@@ -15,19 +15,19 @@ create
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'.
do
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_scope (scope)
+ config.set_scope (a_consumer.scope)
--Todo create a generic OAUTH_20_GENERIC_API
create oauth_api.make (a_consumer.endpoint, a_consumer.authorize_url, a_consumer.extractor)
api_service := oauth_api.create_service (config)
end
- initilize (a_consumer: CMS_OAUTH_CONSUMER)
+ initilize (a_consumer: CMS_OAUTH_20_CONSUMER)
do
--Use configuration values if any if not defaul
api_key := a_consumer.api_key
diff --git a/modules/login/cms_user_oauth_api.e b/modules/login/cms_user_oauth_api.e
deleted file mode 100644
index 4e2ed38..0000000
--- a/modules/login/cms_user_oauth_api.e
+++ /dev/null
@@ -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
diff --git a/modules/login/filter/oauth_filter.e b/modules/login/filter/cms_oauth_20_filter.e
similarity index 71%
rename from modules/login/filter/oauth_filter.e
rename to modules/login/filter/cms_oauth_20_filter.e
index d7c1f45..2750615 100644
--- a/modules/login/filter/oauth_filter.e
+++ b/modules/login/filter/cms_oauth_20_filter.e
@@ -1,10 +1,10 @@
note
- description: "Summary description for {OAUTH_FILTER}."
+ description: "Summary description for {CMS_OAUTH_20_FILTER}."
date: "$Date$"
revision: "$Revision$"
class
- OAUTH_FILTER
+ CMS_OAUTH_20_FILTER
inherit
WSF_URI_TEMPLATE_HANDLER
@@ -20,13 +20,13 @@ create
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
make_handler (a_api)
user_oauth_api := a_user_oauth_api
end
- user_oauth_api: CMS_USER_OAUTH_API
+ user_oauth_api: CMS_OAUTH_20_API
feature -- Basic operations
@@ -41,9 +41,9 @@ feature -- Basic operations
-- end
-- A valid user
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
- 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)
execute_next (req, res)
else
diff --git a/modules/login/persistence/cms_oauth_20_generic_api.e b/modules/login/persistence/cms_oauth_20_generic_api.e
index 149c340..9de5716 100644
--- a/modules/login/persistence/cms_oauth_20_generic_api.e
+++ b/modules/login/persistence/cms_oauth_20_generic_api.e
@@ -51,18 +51,18 @@ feature -- Access
end
end
- access_token_verb: READABLE_STRING_GENERAL
+ access_token_verb: STRING_32
do
Result := "POST"
end
- access_token_endpoint: READABLE_STRING_GENERAL
+ access_token_endpoint: STRING_32
-- Url that receives the access token request
do
create {STRING_32} Result.make_from_string (endpoint)
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
local
l_result: STRING_32
diff --git a/modules/login/persistence/cms_user_oauth_storage_i.e b/modules/login/persistence/cms_oauth_20_storage_i.e
similarity index 51%
rename from modules/login/persistence/cms_user_oauth_storage_i.e
rename to modules/login/persistence/cms_oauth_20_storage_i.e
index 6011ee7..2357707 100644
--- a/modules/login/persistence/cms_user_oauth_storage_i.e
+++ b/modules/login/persistence/cms_oauth_20_storage_i.e
@@ -1,10 +1,12 @@
note
- description: "Summary description for {CMS_USER_OAUTH_STORAGE_I}."
+ description: "[
+ API to handle OAUTH storage
+ ]"
date: "$Date$"
revision: "$Revision$"
deferred class
- CMS_USER_OAUTH_STORAGE_I
+ CMS_OAUTH_20_STORAGE_I
inherit
SHARED_LOGGER
@@ -16,27 +18,39 @@ feature -- Error Handling
deferred
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
- -- CMS User with Oauth credential by id if any.
+ -- Retrieve a user by id `a_uid' for the consumer `a_consumer', if aby.
deferred
end
- user_by_oauth2_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.
+ user_oauth2_by_token (a_token: READABLE_STRING_32; a_consumer_table: READABLE_STRING_32): detachable CMS_USER
+ -- Retrieve a user by token `a_token' for the consumer `a_consumer'.
deferred
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
end
+feature -- Access: Consumers
+
oauth2_consumers: LIST [STRING]
deferred
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
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)
diff --git a/modules/login/persistence/cms_user_oauth_storage_null.e b/modules/login/persistence/cms_oauth_20_storage_null.e
similarity index 61%
rename from modules/login/persistence/cms_user_oauth_storage_null.e
rename to modules/login/persistence/cms_oauth_20_storage_null.e
index a907093..d15d092 100644
--- a/modules/login/persistence/cms_user_oauth_storage_null.e
+++ b/modules/login/persistence/cms_oauth_20_storage_null.e
@@ -1,15 +1,15 @@
note
- description: "Summary description for {CMS_USER_OAUTH_STORAGE_NULL}."
+ description: "Summary description for {CMS_OAUTH_20_STORAGE_NULL}."
author: ""
date: "$Date$"
revision: "$Revision$"
class
- CMS_USER_OAUTH_STORAGE_NULL
+ CMS_OAUTH_20_STORAGE_NULL
inherit
- CMS_USER_OAUTH_STORAGE_I
+ CMS_OAUTH_20_STORAGE_I
feature -- Error handler
@@ -20,27 +20,39 @@ feature -- Error handler
create Result.make
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
-- CMS User with Oauth credential by id if any.
do
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.
do
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
end
+feature -- Access: Consumers
+
oauth2_consumers: LIST [STRING]
do
create {ARRAYED_LIST[STRING]} Result.make (0)
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
new_user_oauth2 (a_token: READABLE_STRING_32; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_32)
diff --git a/modules/login/persistence/cms_user_oauth_storage_sql.e b/modules/login/persistence/cms_oauth_20_storage_sql.e
similarity index 54%
rename from modules/login/persistence/cms_user_oauth_storage_sql.e
rename to modules/login/persistence/cms_oauth_20_storage_sql.e
index c0585f6..ee92e32 100644
--- a/modules/login/persistence/cms_user_oauth_storage_sql.e
+++ b/modules/login/persistence/cms_oauth_20_storage_sql.e
@@ -1,17 +1,17 @@
note
- description: "Summary description for {CMS_USER_OAUTH_STORAGE_SQL}."
+ description: "Summary description for {CMS_OAUTH_20_STORAGE_SQL}."
date: "$Date$"
revision: "$Revision$"
class
- CMS_USER_OAUTH_STORAGE_SQL
+ CMS_OAUTH_20_STORAGE_SQL
inherit
- CMS_USER_OAUTH_STORAGE_I
+ CMS_OAUTH_20_STORAGE_I
CMS_PROXY_STORAGE_SQL
- CMS_USER_OAUTH_STORAGE_I
+ CMS_OAUTH_20_STORAGE_I
CMS_STORAGE_SQL_I
@@ -20,29 +20,29 @@ inherit
create
make
-feature -- Access User Outh Gmail
+feature -- Access User Outh
-
- 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.
local
l_list: LIST[STRING]
do
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
from
l_list.start
until
l_list.after or attached Result
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
end
l_list.forth
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
--
local
l_parameters: STRING_TABLE [detachable ANY]
@@ -53,7 +53,7 @@ feature -- Access User Outh Gmail
create l_parameters.make (1)
l_parameters.put (a_uid, "uid")
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)
if sql_rows_count = 1 then
Result := fetch_user
@@ -62,7 +62,7 @@ feature -- Access User Outh Gmail
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
--
local
l_parameters: STRING_TABLE [detachable ANY]
@@ -73,7 +73,7 @@ feature -- Access User Outh Gmail
create l_parameters.make (1)
l_parameters.put (a_token, "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)
if sql_rows_count = 1 then
Result := fetch_user
@@ -82,6 +82,9 @@ feature -- Access User Outh Gmail
end
end
+
+feature --Access: Consumers
+
oauth2_consumers: LIST[STRING]
-- Return a list of consumers, or empty
do
@@ -103,9 +106,45 @@ feature -- Access User Outh Gmail
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.
-- .
local
@@ -123,12 +162,12 @@ feature -- Change: User Oauth2 Gmail
l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date")
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_commit_transaction
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.
--
local
@@ -145,11 +184,49 @@ feature -- Change: User Oauth2 Gmail
l_parameters.put (a_user_profile, "profile")
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_commit_transaction
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
fetch_user: detachable CMS_USER
@@ -191,15 +268,28 @@ feature {NONE} -- Implementation: User
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_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_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_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