[TBT][Oauth][TSAM-3828,TSAM-][added prompt and access_type using oauth2_request_add_c... 41/75741/1
authorAmlan Chowdhury <amlan.c@samsung.com>
Tue, 21 Jun 2016 07:54:21 +0000 (13:54 +0600)
committerAmlan Chowdhury <amlan.c@samsung.com>
Tue, 21 Jun 2016 08:02:32 +0000 (14:02 +0600)
Signed-off-by: Amlan Chowdhury <amlan.c@samsung.com>
Change-Id: Ic768f6119ea0416e544fc43f3350227602f8ea0d

release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk
release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk
tbtcoreapp/src/view/tbt-oauth2-info-view.c
tbtcoreapp/src/view/tbt-oauth2-view.c

index 8a742673261f96e2f7d9939f2e7fed8dd404b150..6dc1f7d60077bb0250fc35824acbd0a0a3f7f6e7 100644 (file)
Binary files a/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk and b/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk differ
index 86a18465157818f41dd60e1de46cb9af87d8eb79..67bfff99f1fbad90ddc958d2bd52a7cad55222e5 100644 (file)
Binary files a/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk and b/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk differ
index f4e71e97cc21bbf7fa6113c2c3854e805e3b6b0d..e82ed8a103d5b75decb37c06bc92b1065d584e85 100644 (file)
@@ -130,9 +130,9 @@ void _oauth2_info_show(void* data)
        elm_object_part_text_set(this->view->layout, "info5", str);
        SAFE_DELETE(str);
 
-       str = format_string("State :  %s",this->state);
-       elm_object_part_text_set(this->view->layout, "info6", str);
-       SAFE_DELETE(str);
+//     str = format_string("State :  %s",this->state);
+//     elm_object_part_text_set(this->view->layout, "info6", str);
+//     SAFE_DELETE(str);
 
 }
 
index 7f9f502c5f0b98b7d9f9e331c014a91d0bfdb670..6c0c5d376659ad53e671126980b4e40e74956446 100644 (file)
 //#define GOOGLE_CLIENT_ID "670877175811-sfjbiiambdqg411db9472u13ko89m972.apps.googleusercontent.com"
 //#define GOOGLE_CLIENT_SECRET "FHPYeaQnAD2nFEA7yyJac2SS"
 
-
 #define GOOGLE_CLIENT_ID "670877175811-fneddq3cnvgajhalsndlqargbft6tn5j.apps.googleusercontent.com"
 #define GOOGLE_CLIENT_SECRET "AIRkuD9jcPEtaHwDZlvW-pwr"
 
-
 #define OAUTH2_TYPE_STR(k) #k
 
 
 typedef enum {
        GOOGLE_OAUTH2_CODE,
+       GOOGLE_OAUTH2_CHECK_STATE,
+
        ALL_OAUTH2_TYPE
 } oauth2_type_e;
 
@@ -82,10 +82,13 @@ struct _oauth2_view
        const char *scope;
        const char *state;
        const char *custom_data;
+       oauth2_type_e auth_type;
+
 };
 
 static char *oauth2_list[1024] = {
                OAUTH2_TYPE_STR(GOOGLE_OAUTH2_CODE),
+               OAUTH2_TYPE_STR(GOOGLE_OAUTH2_CHECK_STATE)
 };
 
 static void _app_destroy_cb(void* this);
@@ -100,6 +103,7 @@ static char* strip_google_json(const char *s);
 static void show_google_auth_output(void* user_data);
 static void oauth2_info_button_pressed_cb(void *data, Evas_Object *obj, void *event_info);
 static char* get_oauth2_error(oauth2_error_e error);
+static void _oauth2_auth_grant_cb(oauth2_response_h response, void *user_data);
 
 
 /**
@@ -228,6 +232,12 @@ static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
 
        if(!strcmp(enum_text, OAUTH2_TYPE_STR(GOOGLE_OAUTH2_CODE)))
        {
+               this->auth_type = GOOGLE_OAUTH2_CODE;
+               start_google_oauth_code(this);
+       }
+       else if(!strcmp(enum_text, OAUTH2_TYPE_STR(GOOGLE_OAUTH2_CHECK_STATE)))
+       {
+               this->auth_type = GOOGLE_OAUTH2_CHECK_STATE;
                start_google_oauth_code(this);
        }
 }
@@ -242,7 +252,7 @@ static void list_selected_cb(void *data, Evas_Object *obj, void *event_info)
  */
 static void start_google_oauth_code(void* data)
 {
-       DBG("clear_chache_button_pressed_cb");
+       DBG("start_google_oauth_code");
        RETM_IF(NULL == data, "data is NULL");
 
        oauth2_view *this = NULL;
@@ -281,19 +291,61 @@ static void start_google_oauth_code(void* data)
        ret = oauth2_request_set_response_type(request, OAUTH2_RESPONSE_TYPE_CODE);
        RETM_IF(ret != OAUTH2_ERROR_NONE, "oauth2_request_set_response_type error: %s", get_oauth2_error(ret));
 
-       ret = oauth2_request_add_custom_data(request, "c_key", "c_val");
+       ret = oauth2_request_add_custom_data(request, "access_type", "offline");
        RETM_IF(ret != OAUTH2_ERROR_NONE, "oauth2_request_add_custom_data error: %s", get_oauth2_error(ret));
 
+       ret = oauth2_request_add_custom_data(request, "prompt", "consent");
+       RETM_IF(ret != OAUTH2_ERROR_NONE, "oauth2_request_add_custom_data error: %s", get_oauth2_error(ret));
+
+       ret = oauth2_request_set_state(request, "test_state");
+       RETM_IF(ret != OAUTH2_ERROR_NONE, "oauth2_request_set_state error: %s", get_oauth2_error(ret));
+
+
 
        if (mgr && request)
        {
                this->oauth2_mgr = mgr;
-               ret = oauth2_manager_request_token(mgr, request, token_response_cb, this);
-               RETM_IF(ret != OAUTH2_ERROR_NONE, "oauth2_manager_request_token error: %s", get_oauth2_error(ret));
+
+               if(this->auth_type == GOOGLE_OAUTH2_CHECK_STATE)
+               {
+                       elm_object_disabled_set(this->btn_oauth2_info, true);
+                       ret = oauth2_manager_request_authorization_grant(mgr, request, _oauth2_auth_grant_cb, this);
+                       DBG("oauth2_manager_request_authorization_grant error: %s", get_oauth2_error(ret));
+               }
+               else if(this->auth_type == GOOGLE_OAUTH2_CODE)
+               {
+                       elm_object_disabled_set(this->btn_oauth2_info, false);
+                       ret = oauth2_manager_request_token(mgr, request, token_response_cb, this);
+                       DBG("oauth2_manager_request_token error: %s", get_oauth2_error(ret));
+               }
+
        }
 }
 
 
+static void _oauth2_auth_grant_cb(oauth2_response_h response, void *user_data)
+{
+       DBG("_oauth2_auth_grant_cb");
+       RETM_IF(NULL == user_data, "data is NULL");
+
+       oauth2_view *this = NULL;
+       this = (oauth2_view*) user_data;
+       RETM_IF(NULL == this, "view is NULL");
+
+       oauth2_error_e result;
+
+
+       char* state = NULL;
+       result = oauth2_response_get_state(response, &state);
+       RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_state error: %s", get_oauth2_error(result));
+       RETM_IF(NULL == state, "state NULL!");
+       this->state = state;
+
+       char str[128];
+       snprintf(str, sizeof(str), "%s%s", "state : ", this->state);
+       elm_object_text_set(this->google_desc_obj, str);
+}
+
 /**
  * @function           token_response_cb
  * @since_tizen                2.3
@@ -318,9 +370,18 @@ static void token_response_cb(oauth2_response_h response, void *user_data)
        RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_token_type error: %s", get_oauth2_error(result));
        RETM_IF(NULL == token_type, "token_type NULL!");
        this->token_type = token_type;
+       DBG("token type : %s", token_type);
 
        char *ref_token = NULL;
        result = oauth2_response_get_refresh_token(response, &ref_token);
+       if(result != OAUTH2_ERROR_NONE)
+       {
+               ERR("oauth2_response_get_refresh_token error: %s", get_oauth2_error(result));
+       }
+       if(NULL == ref_token)
+       {
+               ERR("ref_token NULL!");
+       }
        RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_refresh_token error: %s", get_oauth2_error(result));
        RETM_IF(NULL == ref_token, "ref_token NULL!");
        this->refresh_token = ref_token;
@@ -338,16 +399,16 @@ static void token_response_cb(oauth2_response_h response, void *user_data)
        //RETM_IF(NULL == scope, "scope NULL!");
        this->scope = scope;
 
-       char* state = NULL;
-       result = oauth2_response_get_state(response, &state);
-       //RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_state error: %s", get_oauth2_error(result));
-       //RETM_IF(NULL == state, "state NULL!");
-       this->state = state;
+//     char* state = NULL;
+//     result = oauth2_response_get_state(response, &state);
+//     RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_state error: %s", get_oauth2_error(result));
+//     RETM_IF(NULL == state, "state NULL!");
+//     this->state = state;
        
        char *acc_token = NULL;
        result = oauth2_response_get_access_token(response, &acc_token);
        RETM_IF(result != OAUTH2_ERROR_NONE, "oauth2_response_get_access_token error: %s", get_oauth2_error(result));
-       //RETM_IF(NULL == acc_token, "acc_token NULL!");
+       RETM_IF(NULL == acc_token, "acc_token NULL!");
        this->access_token = acc_token;