Added new API which use Auth URL 31/302231/8 accepted/tizen_unified_dev accepted/tizen_unified_riscv accepted/tizen/unified/20231215.165141 accepted/tizen/unified/dev/20240620.003458 accepted/tizen/unified/riscv/20231226.211033
authorSundaram Bhupathi <s.bhupathi@samsung.com>
Fri, 1 Dec 2023 12:37:02 +0000 (18:07 +0530)
committerSundaram Bhupathi <s.bhupathi@samsung.com>
Tue, 12 Dec 2023 07:07:55 +0000 (12:37 +0530)
Change-Id: I4717deb403f1e92c542166fb338815b01049d691

include/oauth2_manager.h
src/oauth2_manager.c
src/oauth2_private.h

index a702f5d1962daa156e1687f822b09e3e33f85c3a..735fed66f45aa27e2c5974d2104dcca863ce26ef 100755 (executable)
@@ -126,6 +126,51 @@ typedef void (*oauth2_token_cb)(oauth2_response_h response, void *user_data);
  */
 OAUTH2_API int oauth2_manager_request_token(oauth2_manager_h handle, oauth2_request_h request, oauth2_token_cb callback, void *user_data);
 
+/**
+ * @brief Called when the oauth2_manager_request_token_auth_url() response comes.
+ * @since_tizen 9.0
+ * @remarks The @a response must be released using oauth2_response_destroy().
+ *
+ * @param[in] response The response
+ * @param[in] user_data The user data passed from the callback function
+ *
+ * @pre oauth2_manager_request_token_auth_url() must be called to get this callback invoked.
+ * @see oauth2_manager_request_token_auth_url()
+ */
+typedef void (*oauth2_token_auth_url_cb)(oauth2_response_h response, void *user_data);
+
+/**
+ * @brief Requests OAuth 2.0 access token with authorization URL.
+ * @details The response is delivered via oauth2_token_auth_url_cb().
+ * @since_tizen 9.0
+ * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
+ * @remarks The "internet" privilege is required to call this API. Note, only one pending request is allowed.
+ *
+ * @param[in] handle   The oauth2 manager handle.
+ * @param[in] request  The request handle.
+ * @param[in] callback The callback to receive response.
+ * @param[in] response_url  The response URL after successful Google Sign-in which contains the token.
+ * @param[in] user_data  The user data to be passed to the callback function.
+ *
+ * @return     @c 0 on success,
+ *             otherwise a negative error value
+ * @retval     #OAUTH2_ERROR_NONE               Successful
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
+ * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.
+ * @retval     #OAUTH2_ERROR_OUT_OF_MEMORY Out of memory.
+ * @retval     #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.
+ * @retval     #OAUTH2_ERROR_PARSE_FAILED Parsing failed.
+ * @retval     #OAUTH2_ERROR_NETWORK_ERROR Network Error.
+ * @retval     #OAUTH2_ERROR_UNKNOWN Unknown system error.
+ *
+ * @see oauth2_token_auth_url_cb()
+ * @see oauth2_manager_create()
+ * @see oauth2_request_create()
+ */
+OAUTH2_API int oauth2_manager_request_token_auth_url(oauth2_manager_h handle, oauth2_request_h request, oauth2_token_auth_url_cb callback, char *response_url, void *user_data);
+
 /**
  * @brief Called when oauth2_manager_request_authorization_grant() response comes.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
index 92c48b72aa9cce13cc031fc5d8816491ecd83c44..9617cfc0213555f32099af16766f5e0b6fdc41cc 100755 (executable)
@@ -161,6 +161,7 @@ static void
 __reset_all_cb(oauth2_manager_s *mgr_handle)
 {
        mgr_handle->token_cb = NULL;
+       mgr_handle->token_auth_url_cb = NULL;
        mgr_handle->grant_cb = NULL;
        mgr_handle->access_token_cb = NULL;
        mgr_handle->refresh_cb = NULL;
@@ -318,6 +319,14 @@ __send_response_to_caller(oauth2_manager_s *mgr_handle)
                                (mgr_handle->response), mgr_handle->user_data);
                } else
                        (mgr_handle->token_cb)(NULL, mgr_handle->user_data);
+       } else if (mgr_handle->token_auth_url_cb) {
+               if (mgr_handle->response) {
+                       OAUTH2_LOG_I("__send_response_to_caller calling \
+                               application cb");
+                       (mgr_handle->token_auth_url_cb)((oauth2_response_h)
+                               (mgr_handle->response), mgr_handle->user_data);
+               } else
+                       (mgr_handle->token_auth_url_cb)(NULL, mgr_handle->user_data);
        } else if (mgr_handle->grant_cb) {
                if (mgr_handle->response) {
                        (mgr_handle->grant_cb)((oauth2_response_h)
@@ -341,9 +350,10 @@ __send_response_to_caller(oauth2_manager_s *mgr_handle)
        }
        __reset_all_cb(mgr_handle);
 
-       eext_object_event_callback_del(mgr_handle->login_win,
-               EEXT_CALLBACK_BACK, __handle_back_key);
-
+       if(!mgr_handle->login_win) {
+               eext_object_event_callback_del(mgr_handle->login_win,
+                       EEXT_CALLBACK_BACK, __handle_back_key);
+       }
        OAUTH2_LOG_I("__send_response_to_caller end");
        return;
 }
@@ -1380,6 +1390,120 @@ oauth2_manager_request_token(oauth2_manager_h handle, oauth2_request_h request,
        /*LCOV_EXCL_STOP*/
 }
 
+OAUTH2_API int
+oauth2_manager_request_token_auth_url(oauth2_manager_h handle, oauth2_request_h request,
+       oauth2_token_auth_url_cb callback, char *response_url, void *user_data)
+{
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "oauth2 feature not supported");
+
+       OAUTH2_RETURN_VAL(callback, {}, OAUTH2_ERROR_INVALID_PARAMETER,
+               "callback is Null");
+
+       OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
+               "handle is Null");
+
+       OAUTH2_RETURN_VAL(request, {}, OAUTH2_ERROR_INVALID_PARAMETER,
+               "request is Null");
+       OAUTH2_RETURN_VAL(response_url, {}, OAUTH2_ERROR_INVALID_PARAMETER,
+               "Response URL is Null");
+       /*LCOV_EXCL_START*/
+
+       OAUTH2_RETURN_VAL(__check_permission(), {}, OAUTH2_ERROR_PERMISSION_DENIED,
+               "permission denied, no internet privilege");
+
+       oauth2_manager_s *mgr_impl = (oauth2_manager_s *)handle;
+       OAUTH2_RETURN_VAL(!mgr_impl->is_active, {},
+               OAUTH2_ERROR_ALREADY_IN_PROGRESS, "Already in progress");
+
+       mgr_impl->request = (oauth2_request_s *)request;
+
+       __reset_all_cb(mgr_impl);
+
+       char *redirect_uri = NULL;
+       bundle_get_str(mgr_impl->request->request_data,
+               OAUTH2_PARAMETER_KEY_REDIRECT_URI, &redirect_uri);
+       if (!redirect_uri) {
+               OAUTH2_LOG_E("Missing mandatory field [%s]",
+                       OAUTH2_PARAMETER_KEY_REDIRECT_URI);
+               return OAUTH2_ERROR_INVALID_PARAMETER;
+       }
+
+       char *grant_type_str = NULL;
+       bundle_get_str(mgr_impl->request->request_data,
+               OAUTH2_PARAMETER_KEY_GRANT_TYPE, &grant_type_str);
+       char *grant_type = __get_grant_type(grant_type_str);
+
+       char *response_type_str = NULL;
+       bundle_get_str(mgr_impl->request->request_data,
+               OAUTH2_PARAMETER_KEY_RESPONSE_TYPE, &response_type_str);
+       char *response_type = __get_response_type(response_type_str);
+
+       if (!grant_type && !response_type) {
+               OAUTH2_LOG_E("[%s] or [%s] must be specified",
+                       OAUTH2_PARAMETER_KEY_GRANT_TYPE,
+                       OAUTH2_PARAMETER_KEY_RESPONSE_TYPE);
+               return OAUTH2_ERROR_INVALID_PARAMETER;
+       }
+
+       mgr_impl->token_auth_url_cb = callback;
+       mgr_impl->user_data = user_data;
+
+       mgr_impl->is_active = TRUE;
+
+       /* For authorization code and implicit, response_type is mentioned */
+       if (response_type) {
+               if (!strcmp(response_type,
+                       OAUTH2_PARAMETER_VAL_RESPONSE_TYPE_CODE) ||
+                       !strcmp(response_type,
+                       OAUTH2_PARAMETER_VAL_RESPONSE_TYPE_TOKEN)) {
+                       mgr_impl->request_func = REQUEST_ACCESS_TOKEN;
+                       _on_auth_grant_received(mgr_impl, response_url);
+
+                       return OAUTH2_ERROR_NONE;
+               }
+       }
+       /*
+        * For resource owner pwd and client credentials, grant_type
+        * is mentioned
+        */
+       else {
+               /*
+                * Here authorization grant handling is out of oauth 2.0 RFC, so
+                * unless a custom auth grant handler is set, we will proceed
+                * with access token request directly
+                */
+               if (!strcmp(grant_type,
+                       OAUTH2_PARAMETER_VAL_GRANT_TYPE_PASSWORD) ||
+                       !strcmp(grant_type,
+                       OAUTH2_PARAMETER_VAL_GRANT_TYPE_CLIENT_CREDENTIALS)) {
+                       /* For pwd: grant_type, username, password, scope */
+                       if (!strcmp(grant_type,
+                               OAUTH2_PARAMETER_VAL_GRANT_TYPE_PASSWORD)) {
+                               _request_access_token_for_grant_type_pwd(
+                                       mgr_impl);
+                       } else {
+                               /*For client cred: grant_type, scope */
+                               __request_access_token_for_client_cred(
+                                       mgr_impl);
+                       }
+
+                       /* _request_access_token() */
+                       return OAUTH2_ERROR_NONE;
+               } else {
+                       /*
+                        * TODO:
+                        * TBD, extension grant_type / response_type support
+                        */
+                       return OAUTH2_ERROR_NOT_SUPPORTED;
+               }
+       }
+
+       /* TODO: TBD, extension grant_type / response_type support */
+       return OAUTH2_ERROR_NOT_SUPPORTED;
+       /*LCOV_EXCL_STOP*/
+}
+
 OAUTH2_API int
 oauth2_manager_request_authorization_grant(oauth2_manager_h handle,
        oauth2_request_h request, oauth2_auth_grant_cb callback,
index 11c436db128825f3da3a4eda17afec00510894f3..9eb43f108f9ff9a23bb3e8f8a3dbe22ba0fb29bd 100755 (executable)
@@ -127,6 +127,7 @@ typedef struct _oauth2_manager_s {
 
 /* callbacks */
        oauth2_token_cb token_cb;
+       oauth2_token_auth_url_cb token_auth_url_cb;
        oauth2_auth_grant_cb grant_cb;
        oauth2_access_token_cb access_token_cb;
        oauth2_refresh_token_cb refresh_cb;