4 * Copyright (c) 2014 - 2015 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
26 #include "service_adaptor_errors.h"
27 #include "service_adaptor_internal.h"
28 #include "sal_service_provider.h"
29 #include "sal_auth_provider.h"
31 API int auth_provider_create(auth_provider_h *provider)
35 auth_provider_h auth_provider = (auth_provider_h) g_malloc0(sizeof(auth_provider_s));
37 auth_provider->oauth1_get_access_token = NULL;
38 auth_provider->oauth1_get_extra_data = NULL;
40 auth_provider->oauth2_get_access_token = NULL;
41 auth_provider->oauth2_get_extra_data = NULL;
43 *provider = auth_provider;
45 return SERVICE_ADAPTOR_ERROR_NONE;
48 API app_control_h auth_provider_message(auth_provider_h provider, const char *operation, void *user_data)
52 app_control_h reply = NULL;
54 RETV_IF(NULL == provider, reply);
56 int ret = SERVICE_ADAPTOR_ERROR_NONE;
58 if (0 == strcmp(operation, OAUTH1_0_GET_ACCESS_TOKEN_URI))
60 app_control_create(&reply);
62 char *access_token = NULL;
63 ret = provider->oauth1_get_access_token(&access_token);
65 if (SERVICE_ADAPTOR_ERROR_NONE != ret)
67 SAL_ERR("oauth1_get_access_token() Fail (%d)", ret);
68 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_FAILURE);
72 app_control_add_extra_data(reply, PLUGIN_RESULT_KEY, PLUGIN_RESULT_VALUE_SUCCESS);
73 app_control_add_extra_data(reply, OAUTH1_0_ACCESS_TOKEN_KEY, access_token);
79 API int auth_provider_add_extra_data(auth_provider_h provider, app_control_h reply)
83 RETV_IF(NULL == provider, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
84 RETV_IF(NULL == reply, SERVICE_ADAPTOR_ERROR_INVALID_PARAMETER);
86 app_control_add_extra_data(reply, PLUGIN_KEY_AUTH, PLUGIN_VALUE_TRUE);
88 if (NULL != provider->oauth1_get_access_token)
90 app_control_add_extra_data(reply, OAUTH1_0_GET_ACCESS_TOKEN_URI, PLUGIN_VALUE_TRUE);
93 if (NULL != provider->oauth1_get_extra_data)
95 app_control_add_extra_data(reply, OAUTH1_0_GET_EXTRA_DATA_URI, PLUGIN_VALUE_TRUE);
98 if (NULL != provider->oauth2_get_access_token)
100 app_control_add_extra_data(reply, OAUTH2_0_GET_ACCESS_TOKEN_URI, PLUGIN_VALUE_TRUE);
103 if (NULL != provider->oauth2_get_extra_data)
105 app_control_add_extra_data(reply, OAUTH2_0_GET_EXTRA_DATA_URI, PLUGIN_VALUE_TRUE);
108 return SERVICE_ADAPTOR_ERROR_NONE;