Sync with latest code 19/71219/2 accepted/tizen/common/20160530.132242 accepted/tizen/mobile/20160525.062440 accepted/tizen/wearable/20160525.062439 submit/tizen_common/20160530.122415 submit/tizen_mobile/20160525.042932 submit/tizen_wearable/20160525.042944
authorManasij Sur Roy <manasij.r@samsung.com>
Tue, 24 May 2016 11:57:17 +0000 (17:27 +0530)
committerManasij Sur Roy <manasij.r@samsung.com>
Tue, 24 May 2016 12:02:03 +0000 (17:32 +0530)
Change-Id: I58ae7b0d636fe565558473fce576936e303d248e
Signed-off-by: Manasij Sur Roy <manasij.r@samsung.com>
13 files changed:
.gitignore [new file with mode: 0644]
doc/liboauth2_doc.h
include/oauth2.h
include/oauth2_error.h
include/oauth2_manager.h
include/oauth2_request.h
include/oauth2_response.h
include/oauth2_types.h
packaging/oauth2.spec
src/CMakeLists.txt
src/oauth2_manager.c
src/oauth2_request.c
src/oauth2_util.c

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..080e5b2
--- /dev/null
@@ -0,0 +1,5 @@
+*.config
+*.creator
+*.user
+*.files
+*.includes
index 3ec5116b9fb5bc4f90ac643abddddb6c278e674e..a3477d3e35d04ed6df682f25e2e03ea8fe724baf 100644 (file)
@@ -19,9 +19,9 @@
 #define __OAUTH2_DOC_H__
 
 /**
- * @defgroup  CAPI_OAUTH2_MODULE oauth2
+ * @defgroup  CAPI_OAUTH2_MODULE OAuth 2.0
  * @ingroup   CAPI_ACCOUNT_FRAMEWORK
- * @brief     The oauth2 APIs provide easy way to gain access token between server and client.
+ * @brief     The OAuth 2.0 APIs provide easy way to gain access token between server and client.
  *
  * @section   CAPI_OAUTH2_HEADER Required Header
  *  \#include <oauth2.h>
  * @section CAPI_OAUTH2_MODULE_OVERVIEW Overview
  * The OAuth 2.0 authorization framework enables a third-party application to obtain limited access to an HTTP service, either on behalf of a resource owner by orchestrating an approval interaction between the resource owner and the HTTP service, or by allowing the third-party application to obtain access on its own behalf.
  *
+ * @if WEARABLE
+ * @section CAPI_OAUTH2_MODULE_FEATURE Related Features
+ * This API is related with the following features:
+ *  - http://tizen.org/feature/network.internet
+ *
+ * It is recommended to design feature related codes in your application for reliability.\n
+ *
+ * You can check if a device supports the related features for this API by using @ref CAPI_SYSTEM_SYSTEM_INFO_MODULE, thereby controlling the procedure of your application.\n
+ *
+ * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n
+ *
+ * More details on featuring your application can be found from <a href="../org.tizen.mobile.native.appprogramming/html/ide_sdk_tools/feature_element.htm"><b>Feature Element</b>.</a>
+ * @endif
+ *
 */
 
 #endif /* __OAUTH2_DOC_H__  */
index 0bd45cb65ce09cf505ce883a4e66d148c5f1f61c..9b90eb8931e7488f02d9e8103dc63b0b48b24f04 100644 (file)
@@ -26,7 +26,7 @@
 
 /**
  * Tizen OAuth 2.0 Authorization Framework.
- * Refer to http://tools.ietf.org/html/rfc6749 about oauth 2.0. Also service provider document needs to be referred for using end points and additional parameters.
+ * Refer to http://tools.ietf.org/html/rfc6749 about OAuth 2.0. Also service provider document needs to be referred for using end points and additional parameters.
  */
 
 /**
@@ -34,9 +34,9 @@
  * @{
  */
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
 
-#endif /* _OAUTH2_H_ */
+#endif // _OAUTH2_H_
index 8ef8792d673d98a2a00d6d6fe4c75fb1f5e745d1..c4d4563c91186c6ccea5ad4f567dfdb8066e57e7 100755 (executable)
@@ -24,7 +24,7 @@
 
 /**
  * @file oauth2_error.h
- * @brief The oauth 2.0 error APIs are used to get error fields received from server.
+ * @brief The OAuth 2.0 error APIs are used to get error fields received from server.
  * Refer to service provider documentation about the allowed and additional fields.
  */
 
@@ -34,9 +34,9 @@
  */
 
 /**
- * @brief The structure type for OAuth2 Error handle.
+ * @brief The structure type for OAuth 2.0 Error handle.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
- * @privlevel public
+
  */
 typedef struct oauth2_error_s *oauth2_error_h;
 
@@ -114,7 +114,7 @@ OAUTH2_API int oauth2_error_get_uri(oauth2_error_h handle, char **uri);
  */
 OAUTH2_API int oauth2_error_get_custom_data(oauth2_error_h handle, const char *custom_key, char **custom_value);
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
index b560a330b96b186ea6c5acb02248889501f49948..c796ddb7479e74730f10b3f60d87b929387faded 100755 (executable)
@@ -27,7 +27,7 @@
 
 /**
  * @file oauth2_manager.h
- * @brief The main oauth 2.0 handler APIs.
+ * @brief The main OAuth 2.0 handler APIs.
  * @details The Application must use either:
  * oauth2_manager_request_token
  * or
@@ -42,7 +42,7 @@
  */
 
 /**
- * @brief The structure type for OAuth2 Manager handle.
+ * @brief The structure type for OAuth 2.0 Manager handle.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  */
 typedef struct oauth2_manager_s *oauth2_manager_h;
@@ -96,6 +96,7 @@ typedef void (*oauth2_token_cb)(oauth2_response_h response, void *user_data);
  * "internet" privilege is required to call this API. Note, only one pending request is allowed.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle   The oauth2_manager_handle.
  * @param[in] request  The request handle.
@@ -107,6 +108,7 @@ typedef void (*oauth2_token_cb)(oauth2_response_h response, void *user_data);
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.
  * @retval     #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.
  * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  * @retval     #OAUTH2_ERROR_PARSE_FAILED Parsing failed.
  * @retval     #OAUTH2_ERROR_NETWORK_ERROR Network Error.
  * @retval     #OAUTH2_ERROR_UNKNOWN Unknown system error.
@@ -135,6 +137,7 @@ typedef void (*oauth2_auth_grant_cb)(oauth2_response_h response, void *user_data
  * "internet" privilege is required to call this API. Note, only one pending request is allowed at a time.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle   The oauth2_manager handle.
  * @param[in] request  The request handle.
@@ -146,6 +149,7 @@ typedef void (*oauth2_auth_grant_cb)(oauth2_response_h response, void *user_data
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.
  * @retval     #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.
  * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  * @retval     #OAUTH2_ERROR_PARSE_FAILED Parsing failed.
  * @retval     #OAUTH2_ERROR_NETWORK_ERROR Network Error.
  * @retval     #OAUTH2_ERROR_UNKNOWN Unknown system error.
@@ -174,6 +178,7 @@ typedef void (*oauth2_access_token_cb)(oauth2_response_h response, void *user_da
  * "internet" privilege is required to call this API. Note, only one pending request is allowed at a time.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle   The oauth2_manager handle.
  * @param[in] request  The request handle.
@@ -185,6 +190,7 @@ typedef void (*oauth2_access_token_cb)(oauth2_response_h response, void *user_da
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.
  * @retval     #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.
  * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  * @retval     #OAUTH2_ERROR_PARSE_FAILED Parsing failed.
  * @retval     #OAUTH2_ERROR_NETWORK_ERROR Network Error.
  * @retval     #OAUTH2_ERROR_UNKNOWN Unknown system error.
@@ -213,6 +219,7 @@ typedef void (*oauth2_refresh_token_cb)(oauth2_response_h response, void *user_d
  * "internet" privilege is required to call this API. Note, only one pending request is allowed at a time.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle   The oauth2_manager handle.
  * @param[in] request  The request handle.
@@ -224,6 +231,7 @@ typedef void (*oauth2_refresh_token_cb)(oauth2_response_h response, void *user_d
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER Invalid input parameter(s) passed.
  * @retval     #OAUTH2_ERROR_ALREADY_IN_PROGRESS The previous request is already in progress.
  * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  * @retval     #OAUTH2_ERROR_PARSE_FAILED Parsing failed.
  * @retval     #OAUTH2_ERROR_NETWORK_ERROR Network Error.
  * @retval     #OAUTH2_ERROR_UNKNOWN Unknown system error.
@@ -248,6 +256,7 @@ OAUTH2_API bool oauth2_manager_is_request_in_progress(oauth2_manager_h handle);
  * @brief Clears the cookies.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle The oauth2_manager handle.
  *
@@ -256,6 +265,8 @@ OAUTH2_API bool oauth2_manager_is_request_in_progress(oauth2_manager_h handle);
  * @retval     #OAUTH2_ERROR_NONE               Successful
  * @retval     #OAUTH2_ERROR_OUT_OF_MEMORY      Out of Memory
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  */
 OAUTH2_API int oauth2_manager_clear_cookies(oauth2_manager_h handle);
 
@@ -263,6 +274,7 @@ OAUTH2_API int oauth2_manager_clear_cookies(oauth2_manager_h handle);
  * @brief Clears the cache.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  * @privlevel public
+ * @privilege %http://tizen.org/privilege/internet
  *
  * @param[in] handle The oauth2_manager handle.
  *
@@ -271,10 +283,12 @@ OAUTH2_API int oauth2_manager_clear_cookies(oauth2_manager_h handle);
  * @retval     #OAUTH2_ERROR_NONE               Successful
  * @retval     #OAUTH2_ERROR_OUT_OF_MEMORY      Out of Memory
  * @retval     #OAUTH2_ERROR_INVALID_PARAMETER  Invalid parameter
+ * @retval     #OAUTH2_ERROR_PERMISSION_DENIED Permission denied.
+ * @retval     #OAUTH2_ERROR_NOT_SUPPORTED Not supported.
  */
 OAUTH2_API int oauth2_manager_clear_cache(oauth2_manager_h handle);
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
index 527c7aa8387e169633e5ae43d7614f780a18e661..bb060c7a7b7c4e93263ae1af67bf8cdcdc15298d 100755 (executable)
@@ -24,7 +24,7 @@
 
 /**
  * @file oauth2_request.h
- * @brief The oauth 2.0 request APIs are used to set various parameters to send for oauth 2.0.
+ * @brief The OAuth 2.0 request APIs are used to set various parameters to send for OAuth 2.0.
  * Refer to service provider documentation about the allowed and additional fields.
  */
 
@@ -34,7 +34,7 @@
  */
 
 /**
- * @brief The structure type for OAuth2 Request handle.
+ * @brief The structure type for OAuth 2.0 Request handle.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  */
 typedef struct oauth2_request_s *oauth2_request_h;
@@ -604,7 +604,7 @@ OAUTH2_API int oauth2_request_get_password(oauth2_request_h handle, char **passw
  */
 OAUTH2_API int oauth2_request_get_custom_data(oauth2_request_h handle, const char *custom_key, char **custom_value);
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
index 77568f17a1bd1599aaef65cff009c170a7029c39..894bcd545e9db2db8af8904e31c55d5cb1e2ab3c 100755 (executable)
@@ -24,7 +24,7 @@
 
 /**
  * @file oauth2_response.h
- * @brief The oauth 2.0 response APIs are used to get various parameters received from server.
+ * @brief The OAuth 2.0 response APIs are used to get various parameters received from server.
  * Refer to service provider documentation about the allowed and additional fields.
  */
 
@@ -34,7 +34,7 @@
  */
 
 /**
- * @brief The structure type for OAuth2 Response handle.
+ * @brief The structure type for OAuth 2.0 Response handle.
  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  */
 typedef struct oauth2_response_s *oauth2_response_h;
@@ -222,7 +222,7 @@ OAUTH2_API int oauth2_response_get_error(oauth2_response_h handle, oauth2_error_
  */
 OAUTH2_API int oauth2_response_get_custom_data(oauth2_response_h handle, const char *custom_key, char **custom_value);
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
index 70f6ee70235576333e8d53414849af9347c6d878..2a20ebf48de786fce024713c114c9776ec2009e2 100755 (executable)
@@ -22,7 +22,7 @@
 
 /**
  * @file     oauth2_types.h
- * @brief    This file defines common types and enums of oauth2.
+ * @brief    This file defines common types and enums of OAuth 2.0.
  */
 
 /**
  * @see oauth2_request_set_client_authentication_type()
  */
 typedef enum {
-       OAUTH2_CLIENT_AUTHENTICATION_TYPE_MIN = -1,/**< @internal**/
        OAUTH2_CLIENT_AUTHENTICATION_TYPE_BASIC,/**< HTTP Basic Authentication for client authentication.**/
        OAUTH2_CLIENT_AUTHENTICATION_TYPE_DIGEST,/**< HTTP Digest Authentication for client authentication.**/
-       OAUTH2_CLIENT_AUTHENTICATION_TYPE_REQUEST_BODY,/**< Client credentials are sent via request body**/
-       OAUTH2_CLIENT_AUTHENTICATION_TYPE_MAX,/**< @internal**/
-} oauth2_client_authentication_type_e;
+       OAUTH2_CLIENT_AUTHENTICATION_TYPE_REQUEST_BODY/**< Client credentials are sent via request body**/
+}oauth2_client_authentication_type_e;
 
 /**
  * @brief Enumerations to set grant_type.
@@ -57,13 +55,11 @@ typedef enum {
  * @see oauth2_request_set_grant_type()
  */
 typedef enum {
-       OAUTH2_GRANT_TYPE_MIN = -1, /**< @internal**/
        OAUTH2_GRANT_TYPE_AUTH_CODE, /**< Access Token Request for Authorization Code Grant type.**/
        OAUTH2_GRANT_TYPE_PASSWORD, /**< Access Token Request for Resource Owner Password Credentials Grant type.**/
        OAUTH2_GRANT_TYPE_CLIENT_CREDENTIALS, /**< Access Token Request for Client Credentials Grant type.**/
-       OAUTH2_GRANT_TYPE_REFRESH, /**< Refresh Token Request.**/
-       OAUTH2_GRANT_TYPE_MAX, /**< @internal**/
-} oauth2_grant_type_e;
+       OAUTH2_GRANT_TYPE_REFRESH /**< Refresh Token Request.**/
+}oauth2_grant_type_e;
 
 /**
  * @brief Enumerations to set response_type.
@@ -72,34 +68,32 @@ typedef enum {
  * @see oauth2_request_set_response_type()
  */
 typedef enum {
-       OAUTH2_RESPONSE_TYPE_MIN = -1, /**< @internal**/
        OAUTH2_RESPONSE_TYPE_CODE,/**< Requesting an authorization code as response type.**/
-       OAUTH2_RESPONSE_TYPE_TOKEN,/**< Requesting an access token(implicit grant) as response type.**/
-       OAUTH2_RESPONSE_TYPE_MAX, /**< @internal**/
-} oauth2_response_type_e;
+       OAUTH2_RESPONSE_TYPE_TOKEN/**< Requesting an access token(implicit grant) as response type.**/
+}oauth2_response_type_e;
 
 /**
  *  @brief    Enumerations of error codes for oauth2 APIs.
- *  @since_tizen  3.0
+ *  @since_tizen  @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
  */
 typedef enum {
-       OAUTH2_ERROR_NONE                   = TIZEN_ERROR_NONE,                   /**< Successful */
-       OAUTH2_ERROR_OUT_OF_MEMORY             = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
-       OAUTH2_ERROR_INVALID_PARAMETER         = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
+    OAUTH2_ERROR_NONE                   = TIZEN_ERROR_NONE,                   /**< Successful */
+    OAUTH2_ERROR_OUT_OF_MEMORY             = TIZEN_ERROR_OUT_OF_MEMORY,              /**< Out of memory */
+    OAUTH2_ERROR_INVALID_PARAMETER         = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
 
-       OAUTH2_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */
-       OAUTH2_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Operation not supported */
-       OAUTH2_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
-       OAUTH2_ERROR_PARSE_FAILED = TIZEN_ERROR_ACCOUNT_OAUTH | 0x01, /**< Response parse failed */
-       OAUTH2_ERROR_NETWORK_ERROR = TIZEN_ERROR_ACCOUNT_OAUTH | 0x02, /**< Network error */
-       OAUTH2_ERROR_SERVER = TIZEN_ERROR_ACCOUNT_OAUTH | 0x03, /**< Server error */
-       OAUTH2_ERROR_USER_CANCELLED = TIZEN_ERROR_ACCOUNT_OAUTH | 0x04, /**< User cancelled the operation  */
+    OAUTH2_ERROR_ALREADY_IN_PROGRESS = TIZEN_ERROR_ALREADY_IN_PROGRESS, /**< Operation already in progress */
+    OAUTH2_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Operation not supported */
+    OAUTH2_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
+    OAUTH2_ERROR_PARSE_FAILED = TIZEN_ERROR_ACCOUNT_OAUTH | 0x01, /**< Response parse failed */
+    OAUTH2_ERROR_NETWORK_ERROR = TIZEN_ERROR_ACCOUNT_OAUTH | 0x02, /**< Network error */
+    OAUTH2_ERROR_SERVER = TIZEN_ERROR_ACCOUNT_OAUTH | 0x03, /**< Server error */
+    OAUTH2_ERROR_USER_CANCELLED = TIZEN_ERROR_ACCOUNT_OAUTH | 0x04, /**< User cancelled the operation  */
 
-       OAUTH2_ERROR_VALUE_NOT_FOUND = TIZEN_ERROR_ACCOUNT_OAUTH | 0x05,         /**< Value not found */
-       OAUTH2_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN /**< Unknown error */
-} oauth2_error_e;
+    OAUTH2_ERROR_VALUE_NOT_FOUND = TIZEN_ERROR_ACCOUNT_OAUTH | 0x05,    /**< Value not found */
+    OAUTH2_ERROR_UNKNOWN = TIZEN_ERROR_UNKNOWN /**< Unknown error */
+}oauth2_error_e;
 
-/* End of oauth2 APIs */
+/* End of OAuth 2.0 APIs */
 /**
  * @}
  */
index 6f029568405e642e55e02bff82ec3fa32ffb90d5..ef7f167e05303db0b0db17fad9bd9924be7114a7 100644 (file)
@@ -21,6 +21,8 @@ BuildRequires:  pkgconfig(ewebkit2)
 BuildRequires:  pkgconfig(json-glib-1.0)
 BuildRequires:  pkgconfig(elementary)
 BuildRequires:  pkgconfig(tpkp-curl)
+BuildRequires:  pkgconfig(cynara-client)
+BuildRequires:  pkgconfig(capi-system-info)
 
 Requires(post): /sbin/ldconfig
 Requires(postun): /sbin/ldconfig
index ae440e9d5e504e0d72dbdb494c24967bb881f7c4..42d23ce9a4ba87023438615aae24f40bda3d421f 100644 (file)
@@ -24,9 +24,9 @@ endif()
 
 if(USE_CHROMIUM_EFL)
        add_definitions(-DWITH_CHROMIUM)
-       pkg_check_modules(clientpkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common libcurl efl-extension ecore evas chromium-efl json-glib-1.0 elementary  tpkp-curl)
+       pkg_check_modules(clientpkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common libcurl efl-extension ecore evas chromium-efl json-glib-1.0 elementary tpkp-curl cynara-client capi-system-info)
 else()
-       pkg_check_modules(clientpkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common libcurl efl-extension ecore evas ewebkit2 json-glib-1.0 elementary  tpkp-curl)
+       pkg_check_modules(clientpkgs REQUIRED dlog glib-2.0 gio-2.0 gio-unix-2.0 capi-base-common libcurl efl-extension ecore evas ewebkit2 json-glib-1.0 elementary tpkp-curl cynara-client capi-system-info)
 endif()
 
 FOREACH(flag ${clientpkgs_CFLAGS})
index 550d66cdd328d74a6b2b2700204e4ebbe00a6277..f659087175d0065067e3d752e213d8bfc747e368 100644 (file)
 
 #include <efl_extension.h>
 #include <tpkp_curl.h>
+#include <cynara-client.h>
+#include <cynara-error.h>
+#include <system_info.h>
 
 #include "oauth2_manager.h"
 #include "oauth2_util.h"
 #include "oauth2_private.h"
 
+#define NETWORK_FEATURE "tizen.org/feature/network.internet"
+#define INTERNET_PRIVILEGE "http://tizen.org/privilege/internet"
+#define SMACK_LABEL_LEN 255
+
 static void __send_response_to_caller(oauth2_manager_s *mgr_handle);
 static void __convert_tizen_error_to_oauth_error(int tizen_error,
        char *error_desc, oauth2_response_s **response_handle);
@@ -61,10 +68,73 @@ oauth2_manager_destroy(oauth2_manager_h handle)
                "Null Input");
 
        OAUTH2_FREE(handle);
+
+       ewk_shutdown();
        return OAUTH2_ERROR_NONE;
 }
 
 /*LCOV_EXCL_START*/
+static bool
+__is_feature_supported(void)
+{
+       bool supported = FALSE;
+       int ret = system_info_get_platform_bool(NETWORK_FEATURE, &supported);
+       OAUTH2_RETURN_VAL(ret == SYSTEM_INFO_ERROR_NONE, {}, false, "network feature support check failed");
+
+       return supported;
+}
+
+static bool
+__check_permission(void)
+{
+       static int has_internet_permission = -1;
+
+       if (-1 == has_internet_permission) {
+               int ret;
+               char smack_label[SMACK_LABEL_LEN + 1] = {0};
+               char uid[10];
+               FILE *fd;
+               cynara *cynara_h;
+
+               ret = cynara_initialize(&cynara_h, NULL);
+               if (CYNARA_API_SUCCESS != ret) {
+                        OAUTH2_LOG_E("cynara_initialize() Fail(%d)", ret);
+                        return false;
+               }
+
+               fd = fopen("/proc/self/attr/current", "r");
+               if (NULL == fd) {
+                        OAUTH2_LOG_E("fopen() Fail(%d)", errno);
+                        return false;
+               }
+
+               ret = fread(smack_label, sizeof(smack_label), 1, fd);
+               fclose(fd);
+               if (ret < 0) {
+                        OAUTH2_LOG_E("fread() Fail(%d)", ret);
+                        return 0;
+               }
+
+               snprintf(uid, sizeof(uid), "%d", getuid());
+
+               ret = cynara_check(cynara_h, smack_label, "", uid, INTERNET_PRIVILEGE);
+               if (CYNARA_API_ACCESS_ALLOWED == ret)
+                       has_internet_permission = 1;
+               else
+                       has_internet_permission = 0;
+
+               cynara_finish(cynara_h);
+       }
+
+       if (has_internet_permission == 0) {
+               OAUTH2_LOG_E("Privilege denied");
+               return false;
+       }
+
+       OAUTH2_LOG_I("Privilege granted");
+       return true;
+}
+
 static void
 __hide_web_view(oauth2_manager_s *mgr_handle)
 {
@@ -131,11 +201,11 @@ __get_grant_type(char *grant_type_str)
                return NULL;
 
        char *str_val = NULL;
-       int grant_type = OAUTH2_GRANT_TYPE_MIN;
+       int grant_type = OAUTH2_GRANT_TYPE_AUTH_CODE;
        sscanf(grant_type_str, "%d", &grant_type);
 
-       if (grant_type <= OAUTH2_GRANT_TYPE_MIN
-                       || grant_type >= OAUTH2_GRANT_TYPE_MAX) {
+       if (grant_type < OAUTH2_GRANT_TYPE_AUTH_CODE
+                       || grant_type > OAUTH2_GRANT_TYPE_REFRESH) {
                OAUTH2_LOG_E("Invalid grant_type [%d]", grant_type);
                return NULL;
        } else if (grant_type == OAUTH2_GRANT_TYPE_AUTH_CODE)
@@ -158,11 +228,11 @@ __get_response_type(char *response_type_str)
                return NULL;
 
        char *str_val = NULL;
-       int response_type = OAUTH2_RESPONSE_TYPE_MIN;
+       int response_type = OAUTH2_RESPONSE_TYPE_CODE;
        sscanf(response_type_str, "%d", &response_type);
 
-       if (response_type <= OAUTH2_RESPONSE_TYPE_MIN
-                       || response_type >= OAUTH2_RESPONSE_TYPE_MAX) {
+       if (response_type < OAUTH2_RESPONSE_TYPE_CODE
+                       || response_type > OAUTH2_RESPONSE_TYPE_TOKEN) {
                OAUTH2_LOG_E("Invalid response_type [%d]", response_type);
                return NULL;
        } else if (response_type == OAUTH2_RESPONSE_TYPE_CODE)
@@ -331,7 +401,16 @@ __append_to_post_data(CURL *curl_handle, char *post_data, const char *key,
        OAUTH2_LOG_I("__append_to_post_data start");
 
        char *encoded_key = curl_easy_escape(curl_handle, key, 0);
+       if (encoded_key == NULL) {
+               OAUTH2_LOG_I("curl encoded key null");
+               return;
+       }
+
        char *encoded_val = curl_easy_escape(curl_handle, value, 0);
+       if (encoded_val == NULL) {
+               OAUTH2_LOG_I("curl encoded value null");
+               return;
+       }
 
        strncat(post_data, encoded_key, strlen(encoded_key));
        strncat(post_data, "=", 1);
@@ -400,6 +479,10 @@ __parse_acc_token_response(const char *response_json,
 
        oauth2_response_s *response_temp = (oauth2_response_s *)calloc(1,
                sizeof(oauth2_response_s));
+       if (response_temp == NULL) {
+               OAUTH2_LOG_E("Out of memory");
+               return;
+       }
        /*
         * First find if error key is there, if present only fillup
         * oauth2_error_s else fillup oauth2_response_s without
@@ -425,6 +508,7 @@ __parse_acc_token_response(const char *response_json,
                int ret = oauth2_util_get_params(response_json, &params);
                if (ret != OAUTH2_ERROR_NONE && params == NULL) {
                        OAUTH2_LOG_E("Server response parse failed");
+
                        goto CATCH;
                }
                response_temp->response_data = params;
@@ -440,6 +524,7 @@ __parse_acc_token_response(const char *response_json,
        root_node = json_parser_get_root(parser);
        if (root_node == NULL) {
                OAUTH2_LOG_E("json_parser_get_root() failed");
+
                goto CATCH;
        }
 
@@ -447,6 +532,7 @@ __parse_acc_token_response(const char *response_json,
        root_obj = json_node_get_object((JsonNode *) root_node);
        if (root_obj == NULL) {
                OAUTH2_LOG_E("json_node_get_object() failed");
+
                goto CATCH;
        }
 
@@ -469,9 +555,13 @@ __parse_acc_token_response(const char *response_json,
        OAUTH2_LOG_I("__parse_acc_token_response parse finished");
 
        *response = response_temp;
+    response_temp = NULL;
 
 CATCH:
        g_object_unref(parser);
+    if (response_temp != NULL)
+        oauth2_response_destroy((oauth2_response_h)response_temp);
+
        OAUTH2_LOG_I("__parse_acc_token_response end");
 }
 
@@ -796,24 +886,27 @@ _on_auth_grant_received(oauth2_manager_s *mgr_handle, const char *response_url)
                == 0) {
                char *query = NULL;
                ret = oauth2_util_get_query(response_url, &query);
-               if (ret != OAUTH2_ERROR_NONE && query != NULL) {
+               if (ret != OAUTH2_ERROR_NONE && query == NULL) {
                        __convert_tizen_error_to_oauth_error(
                                OAUTH2_ERROR_SERVER,
                                "Server response does not contain query",
                                &(mgr_handle->response));
                        __send_response_to_caller(mgr_handle);
 
+                       bundle_free(params);
+
                        return;
                }
 
                ret = oauth2_util_get_params(query, &params);
-               if (ret != OAUTH2_ERROR_NONE && params != NULL) {
+               if (ret != OAUTH2_ERROR_NONE && params == NULL) {
                        __convert_tizen_error_to_oauth_error(
                                OAUTH2_ERROR_PARSE_FAILED,
                                "Server response parse failed",
                                &(mgr_handle->response));
                        __send_response_to_caller(mgr_handle);
                        OAUTH2_FREE(query);
+
                        return;
                }
 
@@ -822,16 +915,21 @@ _on_auth_grant_received(oauth2_manager_s *mgr_handle, const char *response_url)
                        is_two_step = TRUE;
 
                OAUTH2_FREE(query);
+
        } else if (strcmp(response_type,
                OAUTH2_PARAMETER_VAL_RESPONSE_TYPE_TOKEN) == 0) {
                char *fragment = NULL;
                ret = oauth2_util_get_fragment(response_url, &fragment);
-               if (ret != OAUTH2_ERROR_NONE && fragment != NULL) {
+               if (ret != OAUTH2_ERROR_NONE && fragment == NULL) {
                        __convert_tizen_error_to_oauth_error(
                                OAUTH2_ERROR_SERVER,
                                "Server response does not contain fragment",
                                &(mgr_handle->response));
                        __send_response_to_caller(mgr_handle);
+
+                       if (params)
+                               bundle_free(params);
+
                        return;
                }
 
@@ -842,10 +940,13 @@ _on_auth_grant_received(oauth2_manager_s *mgr_handle, const char *response_url)
                                "Server response parse failed",
                                &(mgr_handle->response));
                        __send_response_to_caller(mgr_handle);
+
                        OAUTH2_FREE(fragment);
+
                        return;
                }
                OAUTH2_FREE(fragment);
+
        } else {
                /* TODO: Handle custom response_type (for eg, Facebook,
                 * Soundcloud supports "token_and_code") */
@@ -879,6 +980,10 @@ _on_auth_grant_received(oauth2_manager_s *mgr_handle, const char *response_url)
                        return;
                }
                _request_access_token_by_code(mgr_handle, code_val);
+
+               if (params)
+                       bundle_free(params);
+
        } else {
                mgr_handle->is_active = FALSE;
                mgr_handle->response = (oauth2_response_s *)calloc(1,
@@ -990,7 +1095,7 @@ __start_auth_grant_request(oauth2_manager_s *mgr_handle)
        elm_object_text_set(mgr_handle->loading_popup, OAUTH2_LOADING_POP_UP_TEXT);
        elm_popup_orient_set(mgr_handle->loading_popup, ELM_POPUP_ORIENT_BOTTOM);
 
-    /* ewk_init(); */
+       ewk_init();
 
        Evas *canvas = NULL;
 
@@ -1017,8 +1122,18 @@ __start_auth_grant_request(oauth2_manager_s *mgr_handle)
                EEXT_CALLBACK_BACK, __handle_back_key, mgr_handle);
 
        ewk_view_url_set(mgr_handle->ewk_view, authorization_url);
-
        evas_object_size_hint_min_set(mgr_handle->ewk_view, 480, 800);
+
+       /*Ecore_X_Screen *screen = ecore_x_default_screen_get();
+       if (screen != NULL) {
+               int w = 0;
+               int h = 0;
+               ecore_x_screen_size_get (screen, &w, &h);
+               LOGI("Screen info = [%d][%d]", w, h);
+
+               evas_object_size_hint_min_set(mgr_handle->ewk_view, w, h);
+       }*/
+
        evas_object_size_hint_weight_set(mgr_handle->ewk_view,
                EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
        evas_object_size_hint_align_set(mgr_handle->ewk_view,
@@ -1055,6 +1170,12 @@ oauth2_manager_request_token(oauth2_manager_h handle, oauth2_request_h request,
        OAUTH2_RETURN_VAL(request, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "request is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       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");
@@ -1164,6 +1285,12 @@ oauth2_manager_request_authorization_grant(oauth2_manager_h handle,
        OAUTH2_RETURN_VAL(request, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "request is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       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");
@@ -1247,6 +1374,12 @@ oauth2_manager_request_access_token(oauth2_manager_h handle,
        OAUTH2_RETURN_VAL(request, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "request is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       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");
@@ -1288,8 +1421,11 @@ oauth2_manager_request_access_token(oauth2_manager_h handle,
                char *code = NULL;
                bundle_get_str(mgr_impl->request->request_data,
                        OAUTH2_PARAMETER_KEY_CODE, &code);
-               if (code)
+               if (code) {
                        _request_access_token_by_code(mgr_impl, code);
+                       return OAUTH2_ERROR_NONE;
+               }
+
        } else {
                /*
                 * For resource owner pwd and client credentials, grant_type
@@ -1403,6 +1539,12 @@ oauth2_manager_refresh_access_token(oauth2_manager_h handle,
        OAUTH2_RETURN_VAL(request, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "request is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       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");
@@ -1466,6 +1608,12 @@ oauth2_manager_clear_cookies(oauth2_manager_h handle)
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "handle is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       OAUTH2_RETURN_VAL(__check_permission(), {}, OAUTH2_ERROR_PERMISSION_DENIED,
+               "permission denied, no internet privilege");
+
        oauth2_manager_s *mgr_impl = (oauth2_manager_s *)handle;
 
        Evas_Object *web_view = mgr_impl->ewk_view;
@@ -1502,6 +1650,12 @@ oauth2_manager_clear_cache(oauth2_manager_h handle)
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "handle is Null");
        /*LCOV_EXCL_START*/
+       OAUTH2_RETURN_VAL(__is_feature_supported(), {}, OAUTH2_ERROR_NOT_SUPPORTED,
+               "network feature not supported");
+
+       OAUTH2_RETURN_VAL(__check_permission(), {}, OAUTH2_ERROR_PERMISSION_DENIED,
+               "permission denied, no internet privilege");
+
        oauth2_manager_s *mgr_impl = (oauth2_manager_s *)handle;
 
        Evas_Object *web_view = mgr_impl->ewk_view;
index 672c1586067256ce0194cd7dc2b16e6c9e92bcc4..4d5f84922ff7bcb85639ebdbbca142b9331ed328 100644 (file)
@@ -176,8 +176,8 @@ oauth2_request_set_response_type(oauth2_request_h handle,
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "NULL handle");
 
-       if (response_type <= OAUTH2_RESPONSE_TYPE_MIN
-                       || response_type >= OAUTH2_RESPONSE_TYPE_MAX) {
+       if (response_type < OAUTH2_RESPONSE_TYPE_CODE
+                       || response_type > OAUTH2_RESPONSE_TYPE_TOKEN) {
                OAUTH2_LOG_E("Invalid response_type [%d]", response_type);
                return OAUTH2_ERROR_INVALID_PARAMETER;
        }
@@ -249,8 +249,8 @@ oauth2_request_set_client_authentication_type(oauth2_request_h handle,
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "NULL handle");
 
-       if (client_auth_type <= OAUTH2_CLIENT_AUTHENTICATION_TYPE_MIN
-               || client_auth_type >= OAUTH2_CLIENT_AUTHENTICATION_TYPE_MAX) {
+       if (client_auth_type < OAUTH2_CLIENT_AUTHENTICATION_TYPE_BASIC
+               || client_auth_type > OAUTH2_CLIENT_AUTHENTICATION_TYPE_REQUEST_BODY) {
                OAUTH2_LOG_E("Invalid client_auth_type [%d]", client_auth_type);
                return OAUTH2_ERROR_INVALID_PARAMETER;
        }
@@ -321,8 +321,8 @@ oauth2_request_set_grant_type(oauth2_request_h handle,
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "NULL handle");
 
-       if (grant_type <= OAUTH2_GRANT_TYPE_MIN
-                       || grant_type >= OAUTH2_GRANT_TYPE_MAX) {
+       if (grant_type < OAUTH2_GRANT_TYPE_AUTH_CODE
+                       || grant_type > OAUTH2_GRANT_TYPE_REFRESH) {
                OAUTH2_LOG_E("Invalid grant_type [%d]", grant_type);
                return OAUTH2_ERROR_INVALID_PARAMETER;
        }
@@ -531,6 +531,7 @@ oauth2_request_get_response_type(oauth2_request_h handle,
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "NULL handle");
 
+       int res;
        oauth2_request_s *request_data_temp = (oauth2_request_s *)handle;
 
        char *val = NULL;
@@ -539,7 +540,9 @@ oauth2_request_get_response_type(oauth2_request_h handle,
        if (!val)
                return OAUTH2_ERROR_VALUE_NOT_FOUND;
 
-       sscanf(val, "%d", response_type);
+       sscanf(val, "%d", &res);
+       *response_type = (oauth2_response_type_e) res;
+
        return OAUTH2_ERROR_NONE;
 }
 
@@ -622,6 +625,7 @@ oauth2_request_get_grant_type(oauth2_request_h handle,
        OAUTH2_RETURN_VAL(handle, {}, OAUTH2_ERROR_INVALID_PARAMETER,
                "NULL handle");
 
+       int res;
        oauth2_request_s *request_data_temp = (oauth2_request_s *)handle;
 
        char *val = NULL;
@@ -630,7 +634,9 @@ oauth2_request_get_grant_type(oauth2_request_h handle,
        if (!val)
                return OAUTH2_ERROR_VALUE_NOT_FOUND;
 
-       sscanf(val, "%d", grant_type);
+       sscanf(val, "%d", &res);
+       *grant_type = (oauth2_grant_type_e) res;
+
        return OAUTH2_ERROR_NONE;
 }
 
index b6898f895d00391fb90f0b3fc108948c01614a0b..da62fcfd9d33c34f092b7477b91a9119f2699c47 100644 (file)
@@ -112,11 +112,13 @@ oauth2_util_get_params(const char *url_part, bundle **params)
                memset(key, '\0', ((eq_ptr - tmp_start) + 1) * sizeof(char));
                strncpy(key, tmp_start, (eq_ptr - tmp_start));
 
-               eq_ptr++;
+               if (eq_ptr != NULL)
+                       eq_ptr++;
 
                key_size = (tmp_end - eq_ptr) + 1;
                char *val = (char *) malloc((key_size) * sizeof(char));
                if (val == NULL) {
+                       OAUTH2_LOG_E("Out of memory");
                        OAUTH2_FREE(key);
                        return OAUTH2_ERROR_OUT_OF_MEMORY;
                }