Add GetAuthToken OpenAPI.

This commit is contained in:
sdk-team
2020-06-18 15:38:53 +08:00
parent e611ec2db4
commit 2070ee03ba
9 changed files with 341 additions and 4 deletions

View File

@@ -31,21 +31,21 @@ DypnsapiClient::DypnsapiClient(const Credentials &credentials, const ClientConfi
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(credentials), configuration)
{
auto locationClient = std::make_shared<LocationClient>(credentials, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "dypns");
}
DypnsapiClient::DypnsapiClient(const std::shared_ptr<CredentialsProvider>& credentialsProvider, const ClientConfiguration & configuration) :
RpcServiceClient(SERVICE_NAME, credentialsProvider, configuration)
{
auto locationClient = std::make_shared<LocationClient>(credentialsProvider, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "dypns");
}
DypnsapiClient::DypnsapiClient(const std::string & accessKeyId, const std::string & accessKeySecret, const ClientConfiguration & configuration) :
RpcServiceClient(SERVICE_NAME, std::make_shared<SimpleCredentialsProvider>(accessKeyId, accessKeySecret), configuration)
{
auto locationClient = std::make_shared<LocationClient>(accessKeyId, accessKeySecret, configuration);
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "");
endpointProvider_ = std::make_shared<EndpointProvider>(locationClient, configuration.regionId(), SERVICE_NAME, "dypns");
}
DypnsapiClient::~DypnsapiClient()
@@ -159,6 +159,42 @@ DypnsapiClient::DescribeVerifySchemeOutcomeCallable DypnsapiClient::describeVeri
return task->get_future();
}
DypnsapiClient::GetAuthTokenOutcome DypnsapiClient::getAuthToken(const GetAuthTokenRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();
if (!endpointOutcome.isSuccess())
return GetAuthTokenOutcome(endpointOutcome.error());
auto outcome = makeRequest(endpointOutcome.result(), request);
if (outcome.isSuccess())
return GetAuthTokenOutcome(GetAuthTokenResult(outcome.result()));
else
return GetAuthTokenOutcome(outcome.error());
}
void DypnsapiClient::getAuthTokenAsync(const GetAuthTokenRequest& request, const GetAuthTokenAsyncHandler& handler, const std::shared_ptr<const AsyncCallerContext>& context) const
{
auto fn = [this, request, handler, context]()
{
handler(this, request, getAuthToken(request), context);
};
asyncExecute(new Runnable(fn));
}
DypnsapiClient::GetAuthTokenOutcomeCallable DypnsapiClient::getAuthTokenCallable(const GetAuthTokenRequest &request) const
{
auto task = std::make_shared<std::packaged_task<GetAuthTokenOutcome()>>(
[this, request]()
{
return this->getAuthToken(request);
});
asyncExecute(new Runnable([task]() { (*task)(); }));
return task->get_future();
}
DypnsapiClient::GetMobileOutcome DypnsapiClient::getMobile(const GetMobileRequest &request) const
{
auto endpointOutcome = endpointProvider_->getEndpoint();

View File

@@ -0,0 +1,95 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/dypnsapi/model/GetAuthTokenRequest.h>
using AlibabaCloud::Dypnsapi::Model::GetAuthTokenRequest;
GetAuthTokenRequest::GetAuthTokenRequest() :
RpcServiceRequest("dypnsapi", "2017-05-25", "GetAuthToken")
{
setMethod(HttpRequest::Method::Post);
}
GetAuthTokenRequest::~GetAuthTokenRequest()
{}
long GetAuthTokenRequest::getResourceOwnerId()const
{
return resourceOwnerId_;
}
void GetAuthTokenRequest::setResourceOwnerId(long resourceOwnerId)
{
resourceOwnerId_ = resourceOwnerId;
setParameter("ResourceOwnerId", std::to_string(resourceOwnerId));
}
std::string GetAuthTokenRequest::getResourceOwnerAccount()const
{
return resourceOwnerAccount_;
}
void GetAuthTokenRequest::setResourceOwnerAccount(const std::string& resourceOwnerAccount)
{
resourceOwnerAccount_ = resourceOwnerAccount;
setParameter("ResourceOwnerAccount", resourceOwnerAccount);
}
std::string GetAuthTokenRequest::getOrigin()const
{
return origin_;
}
void GetAuthTokenRequest::setOrigin(const std::string& origin)
{
origin_ = origin;
setParameter("Origin", origin);
}
long GetAuthTokenRequest::getOwnerId()const
{
return ownerId_;
}
void GetAuthTokenRequest::setOwnerId(long ownerId)
{
ownerId_ = ownerId;
setParameter("OwnerId", std::to_string(ownerId));
}
std::string GetAuthTokenRequest::getUrl()const
{
return url_;
}
void GetAuthTokenRequest::setUrl(const std::string& url)
{
url_ = url;
setParameter("Url", url);
}
std::string GetAuthTokenRequest::getAccessKeyId()const
{
return accessKeyId_;
}
void GetAuthTokenRequest::setAccessKeyId(const std::string& accessKeyId)
{
accessKeyId_ = accessKeyId;
setParameter("AccessKeyId", accessKeyId);
}

View File

@@ -0,0 +1,68 @@
/*
* Copyright 2009-2017 Alibaba Cloud All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <alibabacloud/dypnsapi/model/GetAuthTokenResult.h>
#include <json/json.h>
using namespace AlibabaCloud::Dypnsapi;
using namespace AlibabaCloud::Dypnsapi::Model;
GetAuthTokenResult::GetAuthTokenResult() :
ServiceResult()
{}
GetAuthTokenResult::GetAuthTokenResult(const std::string &payload) :
ServiceResult()
{
parse(payload);
}
GetAuthTokenResult::~GetAuthTokenResult()
{}
void GetAuthTokenResult::parse(const std::string &payload)
{
Json::Reader reader;
Json::Value value;
reader.parse(payload, value);
setRequestId(value["RequestId"].asString());
auto tokenInfoNode = value["TokenInfo"];
if(!tokenInfoNode["JwtToken"].isNull())
tokenInfo_.jwtToken = tokenInfoNode["JwtToken"].asString();
if(!tokenInfoNode["AccessToken"].isNull())
tokenInfo_.accessToken = tokenInfoNode["AccessToken"].asString();
if(!value["Code"].isNull())
code_ = value["Code"].asString();
if(!value["Message"].isNull())
message_ = value["Message"].asString();
}
std::string GetAuthTokenResult::getMessage()const
{
return message_;
}
GetAuthTokenResult::TokenInfo GetAuthTokenResult::getTokenInfo()const
{
return tokenInfo_;
}
std::string GetAuthTokenResult::getCode()const
{
return code_;
}