--- /dev/null
+/*\r
+ * Copyright (c) 2014 - 2023 Samsung Electronics Co., Ltd. All rights reserved.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ *\r
+ */\r
+\r
+#ifndef OAUTH2_EXPERIMENTAL_H_\r
+#define OAUTH2_EXPERIMENTAL_H_\r
+\r
+#include <stdbool.h>\r
+\r
+#include <oauth2_request.h>\r
+#include <oauth2_response.h>\r
+#include <oauth2_error.h>\r
+#include <oauth2_types.h>\r
+\r
+#ifdef __cplusplus\r
+extern "C" {\r
+#endif\r
+\r
+/**\r
+ * @file oauth2_experimental.h\r
+ * @brief The experimental OAuth 2.0 handler APIs.\r
+ * @details The Application must use either:\r
+ * oauth2_manager_request_token\r
+ * or\r
+ * oauth2_manager_request_authorization_grant and then oauth2_manager_request_access_token.\r
+ * One instance handles only one pending request at any given time. If requested again before completion it throws TIZEN_ERROR_ALREADY_IN_PROGRESS.\r
+ * Application must have internet in order to use these APIs.\r
+ */\r
+\r
+\r
+/**\r
+ * @brief Called when the oauth2_manager_request_token_auth_url() response comes.\r
+ * @since_tizen 9.0\r
+ * @remarks The @a response must be released using oauth2_response_destroy().\r
+ *\r
+ * @param[in] response The response\r
+ * @param[in] user_data The user data passed from the callback function\r
+ *\r
+ * @pre oauth2_manager_request_token_auth_url() must be called to get this callback invoked.\r
+ * @see oauth2_manager_request_token_auth_url()\r
+ */\r
+typedef void (*oauth2_token_auth_url_cb)(oauth2_response_h response, void *user_data);\r
+\r
+/**\r
+ * @brief Requests OAuth 2.0 access token with authorization URL.\r
+ * @details The response is delivered via oauth2_token_auth_url_cb().\r
+ * @since_tizen 9.0\r
+ * @privlevel public\r
+ * @privilege %http://tizen.org/privilege/internet\r
+ * @remarks The "internet" privilege is required to call this API. Note, only one pending request is allowed.\r
+ *\r
+ * @param[in] handle The oauth2 manager handle.\r
+ * @param[in] request The request handle.\r
+ * @param[in] callback The callback to receive response.\r
+ * @param[in] response_url The response URL after successful Google Sign-in which contains the token.\r
+ * @param[in] user_data The user data to be passed to the callback function.\r
+ *\r
+ * @return @c 0 on success,\r
+ * otherwise a negative error value\r
+ * @retval #OAUTH2_ERROR_NONE Successful\r
+ * @retval #OAUTH2_ERROR_NOT_SUPPORTED Not supported.\r
+ * @retval #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.\r
+ * @retval #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.\r
+ * @retval #OAUTH2_ERROR_OUT_OF_MEMORY Out of memory.\r
+ * @retval #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.\r
+ * @retval #OAUTH2_ERROR_PARSE_FAILED Parsing failed.\r
+ * @retval #OAUTH2_ERROR_NETWORK_ERROR Network Error.\r
+ * @retval #OAUTH2_ERROR_UNKNOWN Unknown system error.\r
+ *\r
+ * @see oauth2_token_auth_url_cb()\r
+ * @see oauth2_manager_create()\r
+ * @see oauth2_request_create()\r
+ */\r
+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);\r
+\r
+#ifdef __cplusplus\r
+}\r
+#endif\r
+\r
+#endif /* OAUTH2_EXPERIMENTAL_H_ */\r
#include <system_info.h>
#include "oauth2_manager.h"
+#include "oauth2_experimental.h"
#include "oauth2_util.h"
#include "oauth2_private.h"
__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;
(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)
}
__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;
}
/*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,