From: Amlan Chowdhury Date: Tue, 21 Jun 2016 07:54:21 +0000 (+0600) Subject: [TBT][Oauth][TSAM-3828,TSAM-][added prompt and access_type using oauth2_request_add_c... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=bc0f51f482ca15e364e6f16688634ab77cc6b6ef;p=test%2Ftct%2Fnative%2Fbehavior.git [TBT][Oauth][TSAM-3828,TSAM-][added prompt and access_type using oauth2_request_add_custom_data] Signed-off-by: Amlan Chowdhury Change-Id: Ic768f6119ea0416e544fc43f3350227602f8ea0d --- diff --git a/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk b/release/binary-armv7l/org.tizen.tbtcoreapp-1.0.0-arm.tpk index 8a74267..6dc1f7d 100644 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 diff --git a/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk b/release/binary-x86/org.tizen.tbtcoreapp-1.0.0-i386.tpk index 86a1846..67bfff9 100644 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 diff --git a/tbtcoreapp/src/view/tbt-oauth2-info-view.c b/tbtcoreapp/src/view/tbt-oauth2-info-view.c index f4e71e9..e82ed8a 100644 --- a/tbtcoreapp/src/view/tbt-oauth2-info-view.c +++ b/tbtcoreapp/src/view/tbt-oauth2-info-view.c @@ -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); } diff --git a/tbtcoreapp/src/view/tbt-oauth2-view.c b/tbtcoreapp/src/view/tbt-oauth2-view.c index 7f9f502..6c0c5d3 100644 --- a/tbtcoreapp/src/view/tbt-oauth2-view.c +++ b/tbtcoreapp/src/view/tbt-oauth2-view.c @@ -44,16 +44,16 @@ //#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;