From 359344c9dd3b2d5dc6adf6776a8052b85a39080b Mon Sep 17 00:00:00 2001 From: Jocelyn Fiat Date: Thu, 8 Jun 2017 22:16:12 +0200 Subject: [PATCH] Fixed link for Oauth sign with. Added administration pages for OAuth20 module. --- examples/demo/demo.ecf | 5 +- .../demo/launcher/any/application_launcher.e | 19 -- .../launcher/any/application_launcher_i.e | 127 ------------- .../launcher/default/application_launcher.e | 19 -- .../launcher/default/application_launcher_i.e | 26 --- .../modules/oauth20/templates/block_login.tpl | 2 +- modules/oauth20/cms_oauth_20_api.e | 15 +- modules/oauth20/cms_oauth_20_consumer.e | 13 +- modules/oauth20/cms_oauth_20_module.e | 20 +- .../cms_oauth_20_module_administration.e | 178 ++++++++++++++++++ modules/oauth20/cms_oauth_20_workflow.e | 13 +- modules/oauth20/oauth20-safe.ecf | 1 + .../persistence/cms_oauth_20_storage_i.e | 13 +- .../persistence/cms_oauth_20_storage_null.e | 14 +- .../persistence/cms_oauth_20_storage_sql.e | 41 +++- .../oauth20/site/templates/block_login.tpl | 2 +- 16 files changed, 277 insertions(+), 231 deletions(-) delete mode 100644 examples/demo/launcher/any/application_launcher.e delete mode 100644 examples/demo/launcher/any/application_launcher_i.e delete mode 100644 examples/demo/launcher/default/application_launcher.e delete mode 100644 examples/demo/launcher/default/application_launcher_i.e create mode 100644 modules/oauth20/cms_oauth_20_module_administration.e diff --git a/examples/demo/demo.ecf b/examples/demo/demo.ecf index ffc4e67..ebd52ed 100644 --- a/examples/demo/demo.ecf +++ b/examples/demo/demo.ecf @@ -20,7 +20,6 @@ - @@ -28,12 +27,10 @@ - - @@ -42,7 +39,7 @@ - + diff --git a/examples/demo/launcher/any/application_launcher.e b/examples/demo/launcher/any/application_launcher.e deleted file mode 100644 index 095fdc1..0000000 --- a/examples/demo/launcher/any/application_launcher.e +++ /dev/null @@ -1,19 +0,0 @@ -note - description: "[ - Effective class for APPLICATION_LAUNCHER_I - - You can put modification in this class - ]" - date: "$Date$" - revision: "$Revision$" - -class - APPLICATION_LAUNCHER [G -> WSF_EXECUTION create make end] - -inherit - APPLICATION_LAUNCHER_I [G] - -feature -- Custom - -end - diff --git a/examples/demo/launcher/any/application_launcher_i.e b/examples/demo/launcher/any/application_launcher_i.e deleted file mode 100644 index cec830f..0000000 --- a/examples/demo/launcher/any/application_launcher_i.e +++ /dev/null @@ -1,127 +0,0 @@ -note - description: "[ - Specific application launcher - - DO NOT EDIT THIS CLASS - - you can customize APPLICATION_LAUNCHER - ]" - date: "$Date$" - revision: "$Revision$" - -deferred class - APPLICATION_LAUNCHER_I [G -> WSF_EXECUTION create make end] - -inherit - SHARED_EXECUTION_ENVIRONMENT - -feature -- Execution - - launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - nature: like launcher_nature - do - nature := launcher_nature - if nature = Void then - launch_standalone (opts) - elseif nature = nature_standalone then - launch_standalone (opts) - elseif nature = nature_nino then - launch_nino (opts) - elseif nature = nature_cgi then - launch_cgi (opts) - elseif nature = nature_libfcgi then - launch_libfcgi (opts) - else - -- bye bye - (create {EXCEPTIONS}).die (-1) - end - end - -feature {NONE} -- Access - - launcher_nature: detachable READABLE_STRING_8 - -- Initialize the launcher nature - -- either cgi, libfcgi, or nino. - --| We could extend with more connector if needed. - --| and we could use WSF_DEFAULT_SERVICE_LAUNCHER to configure this at compilation time. - local - p: PATH - ext: detachable READABLE_STRING_32 - do - create p.make_from_string (execution_environment.arguments.command_name) - if attached p.entry as l_entry then - ext := l_entry.extension - end - if ext /= Void then - if ext.same_string (nature_standalone) then - Result := nature_standalone - end - if ext.same_string (nature_nino) then - Result := nature_nino - end - if ext.same_string (nature_cgi) then - Result := nature_cgi - end - if ext.same_string (nature_libfcgi) or else ext.same_string ("fcgi") then - Result := nature_libfcgi - end - end - Result := default_nature - end - -feature {NONE} -- standalone - - nature_standalone: STRING = "standalone" - - launch_standalone (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - launcher: WSF_STANDALONE_SERVICE_LAUNCHER [G] - do - create launcher.make_and_launch (opts) - end - -feature {NONE} -- nino - - nature_nino: STRING = "nino" - - launch_nino (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - launcher: WSF_NINO_SERVICE_LAUNCHER [G] - do - create launcher.make_and_launch (opts) - end - -feature {NONE} -- cgi - - nature_cgi: STRING = "cgi" - - launch_cgi (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - launcher: WSF_CGI_SERVICE_LAUNCHER [G] - do - create launcher.make_and_launch (opts) - end - -feature {NONE} -- libfcgi - - nature_libfcgi: STRING = "libfcgi" - - launch_libfcgi (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - launcher: WSF_LIBFCGI_SERVICE_LAUNCHER [G] - do - create launcher.make_and_launch (opts) - end - -feature -- Default - - default_nature: STRING - do - Result := nature_standalone - end - - -end - - diff --git a/examples/demo/launcher/default/application_launcher.e b/examples/demo/launcher/default/application_launcher.e deleted file mode 100644 index 095fdc1..0000000 --- a/examples/demo/launcher/default/application_launcher.e +++ /dev/null @@ -1,19 +0,0 @@ -note - description: "[ - Effective class for APPLICATION_LAUNCHER_I - - You can put modification in this class - ]" - date: "$Date$" - revision: "$Revision$" - -class - APPLICATION_LAUNCHER [G -> WSF_EXECUTION create make end] - -inherit - APPLICATION_LAUNCHER_I [G] - -feature -- Custom - -end - diff --git a/examples/demo/launcher/default/application_launcher_i.e b/examples/demo/launcher/default/application_launcher_i.e deleted file mode 100644 index cfe2b9d..0000000 --- a/examples/demo/launcher/default/application_launcher_i.e +++ /dev/null @@ -1,26 +0,0 @@ -note - description: "[ - Specific application launcher - - DO NOT EDIT THIS CLASS - - you can customize APPLICATION_LAUNCHER - ]" - date: "$Date$" - revision: "$Revision$" - -deferred class - APPLICATION_LAUNCHER_I [G -> WSF_EXECUTION create make end] - -feature -- Execution - - launch (opts: detachable WSF_SERVICE_LAUNCHER_OPTIONS) - local - launcher: WSF_DEFAULT_SERVICE_LAUNCHER [G] - do - create launcher.make_and_launch (opts) - end - -end - - diff --git a/examples/demo/site/modules/oauth20/templates/block_login.tpl b/examples/demo/site/modules/oauth20/templates/block_login.tpl index 44c7bd4..3f7fc6b 100644 --- a/examples/demo/site/modules/oauth20/templates/block_login.tpl +++ b/examples/demo/site/modules/oauth20/templates/block_login.tpl @@ -1,7 +1,7 @@
{foreach item="item" from="$oauth_consumers"} - Login with {$item/}
+ Login with {$item/}
{/foreach}
diff --git a/modules/oauth20/cms_oauth_20_api.e b/modules/oauth20/cms_oauth_20_api.e index cb5ef6a..d4a2669 100644 --- a/modules/oauth20/cms_oauth_20_api.e +++ b/modules/oauth20/cms_oauth_20_api.e @@ -83,13 +83,13 @@ feature -- Access: Consumers OAuth20 Result := oauth_20_storage.oauth2_consumers end - oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER + oauth_consumer_by_name (a_name: READABLE_STRING_GENERAL): 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 + oauth_consumer_by_callback (a_callback: READABLE_STRING_GENERAL): 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) @@ -97,7 +97,12 @@ feature -- Access: Consumers OAuth20 feature -- Change: User OAuth20 - new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL) + save_oauth_consumer (a_cons: CMS_OAUTH_20_CONSUMER) + do + oauth_20_storage.save_oauth_consumer (a_cons) + end + + new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL) -- Add a new user with oauth20 using the consumer `a_consumer'. require has_id: a_user.has_id @@ -105,8 +110,7 @@ feature -- Change: User OAuth20 oauth_20_storage.new_user_oauth2 (a_token, a_user_profile, a_user, a_consumer) end - - update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) + update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) -- Update user `a_user' with oauth2 for the consumer `a_consumer'. require has_id: a_user.has_id @@ -114,7 +118,6 @@ feature -- Change: User OAuth20 oauth_20_storage.update_user_oauth2 (a_token, a_user_profile, a_user, a_consumer_table) end - remove_user_oauth2 (a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) -- Remove user `a_user' with oauth2 for the consumer `a_consumer'. require diff --git a/modules/oauth20/cms_oauth_20_consumer.e b/modules/oauth20/cms_oauth_20_consumer.e index 1e14806..b297194 100644 --- a/modules/oauth20/cms_oauth_20_consumer.e +++ b/modules/oauth20/cms_oauth_20_consumer.e @@ -38,8 +38,18 @@ feature {NONE} -- Initialization set_name ("") end +feature -- Status report + + has_id: BOOLEAN + do + Result := id > 0 + end + feature -- Access + id: INTEGER_64 + -- unique identifier. + endpoint: READABLE_STRING_8 -- Url that receives the access token request. @@ -68,9 +78,6 @@ feature -- Access name: READABLE_STRING_32 -- consumer name. - id: INTEGER_64 - -- unique identifier. - feature -- Element change set_extractor (a_extractor: like extractor) diff --git a/modules/oauth20/cms_oauth_20_module.e b/modules/oauth20/cms_oauth_20_module.e index 2ea9610..8bd65af 100644 --- a/modules/oauth20/cms_oauth_20_module.e +++ b/modules/oauth20/cms_oauth_20_module.e @@ -21,6 +21,8 @@ inherit oauth20_api end + CMS_ADMINISTRABLE + CMS_HOOK_BLOCK SHARED_EXECUTION_ENVIRONMENT @@ -50,6 +52,13 @@ feature -- Access name: STRING = "oauth20" +feature {CMS_EXECUTION} -- Administration + + administration: CMS_OAUTH_20_MODULE_ADMINISTRATION + do + create Result.make (Current) + end + feature {CMS_API} -- Module Initialization initialize (a_api: CMS_API) @@ -130,7 +139,7 @@ feature {CMS_API} -- Module management end end -feature {CMS_API} -- Access: API +feature {CMS_API, CMS_MODULE_ADMINISTRATION} -- Access: API oauth20_api: detachable CMS_OAUTH_20_API -- @@ -280,7 +289,7 @@ feature -- Hooks attached {WSF_STRING} req.cookie (a_oauth20_api.session_token) as l_cookie_token then -- Logout OAuth - create l_cookie.make (a_oauth20_api.session_token, l_cookie_token.value) + create l_cookie.make (a_oauth20_api.session_token, l_cookie_token.url_encoded_value) l_cookie.set_path ("/") l_cookie.set_max_age (-1) res.add_cookie (l_cookie) @@ -386,7 +395,8 @@ feature -- OAuth2 Login with Provider l_cookie: WSF_COOKIE es: CMS_AUTHENTICATION_EMAIL_SERVICE do - if attached {WSF_STRING} req.path_parameter (oauth_callback_path_parameter) as l_callback and then + if + attached {WSF_STRING} req.path_parameter (oauth_callback_path_parameter) as l_callback and then attached {CMS_OAUTH_20_CONSUMER} a_oauth_api.oauth_consumer_by_callback (l_callback.value) as l_consumer and then attached {WSF_STRING} req.query_parameter (oauth_code_query_parameter) as l_code then @@ -411,7 +421,7 @@ feature -- OAuth2 Login with Provider a_oauth_api.update_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name ) else -- create a oauth entry - a_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile, p_user, l_consumer.name ) + a_oauth_api.new_user_oauth2 (l_access_token.token, l_user_profile.to_string_32, p_user, l_consumer.name ) end create l_cookie.make (a_oauth_api.session_token, l_access_token.token) l_cookie.set_max_age (l_access_token.expires_in) @@ -468,7 +478,7 @@ feature -- OAuth2 Login with Provider attached {WSF_STRING} req.form_parameter ("email") as l_email and then attached r.user as l_user then - l_user.set_email (l_email.value) + l_user.set_email (api.utf_8_encoded (l_email.value)) a_oauth_api.new_user_oauth2 ("none", "none", l_user, l_consumer.value ) -- TODO send email? end diff --git a/modules/oauth20/cms_oauth_20_module_administration.e b/modules/oauth20/cms_oauth_20_module_administration.e new file mode 100644 index 0000000..1e1fd67 --- /dev/null +++ b/modules/oauth20/cms_oauth_20_module_administration.e @@ -0,0 +1,178 @@ +note + description: "Summary description for {CMS_OAUTH_20_MODULE_ADMINISTRATION}." + author: "" + date: "$Date$" + revision: "$Revision$" + +class + CMS_OAUTH_20_MODULE_ADMINISTRATION + +inherit + CMS_MODULE_ADMINISTRATION [CMS_OAUTH_20_MODULE] + redefine + setup_hooks, + permissions + end + + CMS_HOOK_MENU_SYSTEM_ALTER + +create + make + +feature -- Access + + permissions: LIST [READABLE_STRING_8] + -- List of permission ids, used by this module, and declared. + do + Result := Precursor + end + +feature {NONE} -- Router/administration + + setup_administration_router (a_router: WSF_ROUTER; a_api: CMS_API) + do + a_router.handle ("/oauth20/", create {WSF_URI_AGENT_HANDLER}.make (agent handle_admin_consumers (a_api, ?, ?)), a_router.methods_head_get_post) + a_router.handle ("/oauth20/{consumer}", create {WSF_URI_TEMPLATE_AGENT_HANDLER}.make (agent handle_admin_consumer (a_api, ?, ?)), a_router.methods_head_get_post) + end + +feature -- Handle + + handle_admin_consumers (a_api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) + local + r: CMS_RESPONSE + s: STRING + do + create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, a_api) + create s.make_empty + s.append ("

Consumers

") + if attached module.oauth20_api as l_oauth20_api then + s.append ("") + end + r.set_main_content (s) + r.execute + end + + handle_admin_consumer (a_api: CMS_API; req: WSF_REQUEST; res: WSF_RESPONSE) + local + r: CMS_RESPONSE + s: STRING + f: CMS_FORM + fset: WSF_FORM_FIELD_SET + tf: WSF_FORM_TEXT_INPUT + l_is_protect_predefined_fields: BOOLEAN + do + if attached {WSF_STRING} req.path_parameter ("consumer") as p_consumer then + if + attached module.oauth20_api as l_oauth20_api and then + attached l_oauth20_api.oauth_consumer_by_name (p_consumer.value) as cons + then + l_is_protect_predefined_fields := cons.has_id + + create {GENERIC_VIEW_CMS_RESPONSE} r.make (req, res, a_api) + r.add_to_primary_tabs (a_api.administration_link ("Consumers", "oauth20/")) + create s.make_empty + s.append ("

Consumer %"" + a_api.html_encoded (cons.name) + "%"

") + create f.make (req.percent_encoded_path_info, "consumer") + f.set_method_post + create tf.make_with_text ("name", cons.name) + tf.set_label ("Name"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + f.extend (tf) + + create fset.make + fset.set_legend ("Enter expected data") + f.extend (fset) + create tf.make_with_text ("api_key", cons.api_key) + tf.set_label ("API key"); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("api_secret", cons.api_secret) + tf.set_label ("API secret") + fset.extend (tf); tf.set_size (70) + + fset.extend (create {WSF_FORM_SUBMIT_INPUT}.make_with_text ("op", "Submit")) + + create fset.make + fset.set_legend ("Predefine settings (change with care)") + f.extend (fset) + + create tf.make_with_text ("authorize_url", cons.authorize_url) + tf.set_label ("Authorize URL"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("callback_name", cons.callback_name) + tf.set_label ("Callback Name"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("endpoint", cons.endpoint) + tf.set_label ("Endpoint"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("extractor", cons.extractor) + tf.set_label ("Extractor"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("protected_resource_url", cons.protected_resource_url) + tf.set_label ("Protected Resource URL"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + create tf.make_with_text ("scope", cons.scope) + tf.set_label ("Scope"); tf.set_is_readonly (l_is_protect_predefined_fields); tf.set_size (70) + fset.extend (tf) + + + if req.is_get_head_request_method then + f.append_to_html (r.wsf_theme, s) + else + f.submit_actions.extend (agent (fd: WSF_FORM_DATA; i_cons: CMS_OAUTH_20_CONSUMER; i_oauth20_api: CMS_OAUTH_20_API; l_output: STRING) + do + if + attached fd.string_item ("api_key") as l_api_key and then + attached fd.string_item ("api_secret") as l_api_secret + then + i_cons.set_api_key (l_api_key) + i_cons.set_api_secret (l_api_secret) + i_oauth20_api.save_oauth_consumer (i_cons) + l_output.append ("

Consumer saved...

") + end + end(?, cons, l_oauth20_api, s) + ); + f.process (r) + f.append_to_html (r.wsf_theme, s) + end + r.set_main_content (s) + else + create {NOT_FOUND_ERROR_CMS_RESPONSE} r.make (req, res, a_api) + end + else + create {BAD_REQUEST_ERROR_CMS_RESPONSE} r.make (req, res, a_api) + end + r.execute + end + + +feature -- Hook + + setup_hooks (a_hooks: CMS_HOOK_CORE_MANAGER) + -- Module hooks configuration. + do + a_hooks.subscribe_to_menu_system_alter_hook (Current) + end + + menu_system_alter (a_menu_system: CMS_MENU_SYSTEM; a_response: CMS_RESPONSE) + -- Hook execution on collection of menu contained by `a_menu_system' + -- for related response `a_response'. + do + if a_response.is_authenticated then + a_menu_system.navigation_menu.extend (create {CMS_LOCAL_LINK}.make ("OAuth20", a_response.api.administration_path_location ("oauth20/"))) +-- if a_response.has_permission (permission__manage_feed_aggregator) then +-- a_menu_system.management_menu.extend_into (a_response.api.administration_link ("Feeds (admin)", "feed_aggregator/"), "Admin", "admin") +-- end + end + end + + +end diff --git a/modules/oauth20/cms_oauth_20_workflow.e b/modules/oauth20/cms_oauth_20_workflow.e index 039020c..209e8d7 100644 --- a/modules/oauth20/cms_oauth_20_workflow.e +++ b/modules/oauth20/cms_oauth_20_workflow.e @@ -38,15 +38,14 @@ feature {NONE} -- Initialization feature -- Access - authorization_url: detachable READABLE_STRING_32 + authorization_url: detachable READABLE_STRING_8 -- Obtain the Authorization URL. do -- Obtain the Authorization URL write_debug_log (generator + ".authorization_url Fetching the Authorization URL..!") if attached api_service.authorization_url (empty_token) as l_authorization_url then - write_debug_log (generator + ".authorization_url: Got the Authorization URL!") write_debug_log (generator + ".authorization_url:" + l_authorization_url) - Result := l_authorization_url.as_string_32 + Result := l_authorization_url end end @@ -77,8 +76,8 @@ feature -- Access end end - user_email: detachable READABLE_STRING_32 - -- Retrieve user email if any. + user_email: detachable READABLE_STRING_8 + -- User email if any. local l_json: JSON_CONFIG do @@ -91,7 +90,7 @@ feature -- Access then Result := l_email.item elseif attached {JSON_STRING} l_json.item ("email") as l_email then - Result := l_email.unescaped_string_32 + Result := l_email.unescaped_string_8 end end end @@ -101,7 +100,7 @@ feature -- Access access_token: detachable OAUTH_TOKEN -- JSON representing the access token. - user_profile: detachable READABLE_STRING_32 + user_profile: detachable READABLE_STRING_8 -- JSON representing the user profiles. feature {NONE} -- Implementation diff --git a/modules/oauth20/oauth20-safe.ecf b/modules/oauth20/oauth20-safe.ecf index d20ea48..3d2eae8 100644 --- a/modules/oauth20/oauth20-safe.ecf +++ b/modules/oauth20/oauth20-safe.ecf @@ -25,6 +25,7 @@ + diff --git a/modules/oauth20/persistence/cms_oauth_20_storage_i.e b/modules/oauth20/persistence/cms_oauth_20_storage_i.e index bd16eb2..6950a76 100644 --- a/modules/oauth20/persistence/cms_oauth_20_storage_i.e +++ b/modules/oauth20/persistence/cms_oauth_20_storage_i.e @@ -46,24 +46,29 @@ feature -- Access: Consumers deferred end - oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER + oauth_consumer_by_name (a_name: READABLE_STRING_GENERAL): 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 + oauth_consumer_by_callback (a_callback: READABLE_STRING_GENERAL): 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_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) + save_oauth_consumer (a_cons: CMS_OAUTH_20_CONSUMER) + -- Save consumer `a_cons`. + deferred + end + + new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) -- Add a new user with oauth2 authentication. deferred end - update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL ) + update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL ) -- Update user `a_user' with oauth2 authentication. deferred end diff --git a/modules/oauth20/persistence/cms_oauth_20_storage_null.e b/modules/oauth20/persistence/cms_oauth_20_storage_null.e index 8ddef02..3628206 100644 --- a/modules/oauth20/persistence/cms_oauth_20_storage_null.e +++ b/modules/oauth20/persistence/cms_oauth_20_storage_null.e @@ -37,7 +37,7 @@ feature -- Access: Users do end - user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_GENERAL ): detachable CMS_USER + user_oauth2_without_consumer_by_token (a_token: READABLE_STRING_GENERAL): detachable CMS_USER do end @@ -48,24 +48,28 @@ feature -- Access: Consumers create {ARRAYED_LIST [STRING]} Result.make (0) end - oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER + oauth_consumer_by_name (a_name: READABLE_STRING_GENERAL): 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 + oauth_consumer_by_callback (a_callback: READABLE_STRING_GENERAL): 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_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) + save_oauth_consumer (a_cons: CMS_OAUTH_20_CONSUMER) + do + end + + new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL) -- Add a new user with oauth2 authentication. do end - update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL ) + update_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer_table: READABLE_STRING_GENERAL ) -- Update user `a_user' with oauth2 authentication. do end diff --git a/modules/oauth20/persistence/cms_oauth_20_storage_sql.e b/modules/oauth20/persistence/cms_oauth_20_storage_sql.e index f7fbfe0..3bcc7c9 100644 --- a/modules/oauth20/persistence/cms_oauth_20_storage_sql.e +++ b/modules/oauth20/persistence/cms_oauth_20_storage_sql.e @@ -148,7 +148,7 @@ feature --Access: Consumers sql_finalize end - oauth_consumer_by_name (a_name: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER + oauth_consumer_by_name (a_name: READABLE_STRING_GENERAL): detachable CMS_OAUTH_20_CONSUMER -- Retrieve a consumer by name `a_name', if any. local l_parameters: STRING_TABLE [detachable ANY] @@ -169,7 +169,7 @@ feature --Access: Consumers sql_finalize end - oauth_consumer_by_callback (a_callback: READABLE_STRING_8): detachable CMS_OAUTH_20_CONSUMER + oauth_consumer_by_callback (a_callback: READABLE_STRING_GENERAL): detachable CMS_OAUTH_20_CONSUMER -- Retrieve a consumer by callback `a_callback', if any. local l_parameters: STRING_TABLE [detachable ANY] @@ -192,7 +192,37 @@ feature --Access: Consumers feature -- Change: User OAuth - new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_32; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL) + save_oauth_consumer (a_cons: CMS_OAUTH_20_CONSUMER) + -- Save consumer `a_cons`. + local + l_parameters: STRING_TABLE [detachable ANY] + do + error_handler.reset + if a_cons.has_id then + create l_parameters.make (10) + l_parameters.put (a_cons.id, "cid") + else + create l_parameters.make (9) + end + l_parameters.put (a_cons.name, "name") + l_parameters.put (a_cons.api_secret, "api_secret") + l_parameters.put (a_cons.api_key, "api_key") + l_parameters.put (a_cons.scope, "scope") + l_parameters.put (a_cons.protected_resource_url, "protected_resource_url") + l_parameters.put (a_cons.callback_name, "callback_name") + l_parameters.put (a_cons.extractor, "extractor") + l_parameters.put (a_cons.authorize_url, "authorize_url") + l_parameters.put (a_cons.endpoint, "endpoint") + + if a_cons.has_id then + sql_modify (sql_update_oauth2_consumers, l_parameters) + else + sql_insert (sql_insert_oauth2_consumers, l_parameters) + end + sql_finalize + end + + new_user_oauth2 (a_token: READABLE_STRING_GENERAL; a_user_profile: READABLE_STRING_GENERAL; a_user: CMS_USER; a_consumer: READABLE_STRING_GENERAL) -- Add a new user with oauth2 authentication. -- . local @@ -210,7 +240,6 @@ feature -- Change: User OAuth l_parameters.put (create {DATE_TIME}.make_now_utc, "utc_date") l_parameters.put (a_user.email, "email") - create l_string.make_from_string (sql_insert_oauth2_template) l_string.replace_substring_all ("$table_name", oauth2_sql_table_name (a_consumer)) sql_insert (l_string, l_parameters) @@ -356,4 +385,8 @@ feature {NONE} -- Consumer Sql_oauth_consumer_name: STRING = "SELECT * FROM oauth2_consumers where name =:name;" + sql_insert_oauth2_consumers: STRING = "INSERT INTO oauth2_consumers (name, api_secret, api_key, scope, protected_resource_url, callback_name, extractor, authorize_url, endpoint) VALUES (:name, :api_secret, :api_key, :scope, :protected_resource_url, :callback_name, :extractor, :authorize_url, :endpoint);" + + sql_update_oauth2_consumers: STRING = "UPDATE oauth2_consumers SET name = :name, api_secret = :api_secret, api_key = :api_key, scope = :scope, protected_resource_url = :protected_resource_url, callback_name = :callback_name, extractor = :extractor, authorize_url = :authorize_url, endpoint = :endpoint WHERE cid = :cid;" + end diff --git a/modules/oauth20/site/templates/block_login.tpl b/modules/oauth20/site/templates/block_login.tpl index 44c7bd4..3f7fc6b 100644 --- a/modules/oauth20/site/templates/block_login.tpl +++ b/modules/oauth20/site/templates/block_login.tpl @@ -1,7 +1,7 @@
{foreach item="item" from="$oauth_consumers"} - Login with {$item/}
+ Login with {$item/}
{/foreach}