cesium-native 0.46.0
Loading...
Searching...
No Matches
OAuth2PKCE.h
1#pragma once
2
3#include "Library.h"
4
5#include <CesiumAsync/AsyncSystem.h>
6#include <CesiumAsync/Future.h>
7#include <CesiumAsync/IAssetAccessor.h>
8#include <CesiumUtility/Result.h>
9
10#include <optional>
11#include <string>
12
13namespace CesiumClientCommon {
14
23 std::string accessToken;
30 std::optional<std::string> refreshToken;
31};
32
40 std::string clientID;
49 std::string redirectPath;
57 std::optional<int> redirectPort = std::nullopt;
66};
67
78class CESIUMCLIENTCOMMON_API OAuth2PKCE {
79public:
110 const CesiumAsync::AsyncSystem& asyncSystem,
111 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
112 const std::string& friendlyApplicationName,
113 const OAuth2ClientOptions& clientOptions,
114 const std::vector<std::string>& scopes,
115 std::function<void(const std::string&)>&& openUrlCallback,
116 const std::string& tokenEndpointUrl,
117 const std::string& authorizeBaseUrl);
118
137 const CesiumAsync::AsyncSystem& asyncSystem,
138 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
139 const OAuth2ClientOptions& clientOptions,
140 const std::string& refreshBaseUrl,
141 const std::string& refreshToken);
142
143private:
145 completeTokenExchange(
146 const CesiumAsync::AsyncSystem& asyncSystem,
147 const std::shared_ptr<CesiumAsync::IAssetAccessor>& pAssetAccessor,
148 const OAuth2ClientOptions& clientOptions,
149 const std::string& tokenEndpointUrl,
150 const std::string& code,
151 const std::string& redirectUrl,
152 const std::string& codeVerifier);
153};
154
155} // namespace CesiumClientCommon
A system for managing asynchronous requests and tasks.
Definition AsyncSystem.h:36
A value that will be available in the future, as produced by AsyncSystem.
Definition Promise.h:12
Class for authenticating with an API that uses OAuth2 Proof of Key Code Exchange (PKCE).
Definition OAuth2PKCE.h:78
static CesiumAsync::Future< CesiumUtility::Result< OAuth2TokenResponse > > authorize(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const std::string &friendlyApplicationName, const OAuth2ClientOptions &clientOptions, const std::vector< std::string > &scopes, std::function< void(const std::string &)> &&openUrlCallback, const std::string &tokenEndpointUrl, const std::string &authorizeBaseUrl)
Initiates the OAuth2 PKCE authentication process.
static CesiumAsync::Future< CesiumUtility::Result< OAuth2TokenResponse > > refresh(const CesiumAsync::AsyncSystem &asyncSystem, const std::shared_ptr< CesiumAsync::IAssetAccessor > &pAssetAccessor, const OAuth2ClientOptions &clientOptions, const std::string &refreshBaseUrl, const std::string &refreshToken)
Attempts to obtain new access and refresh tokens using a refresh token obtained from a previous call ...
Shared classes for interacting with Cesium ion and iTwin APIs.
Options used to configure the OAuth2 authentication process.
Definition OAuth2PKCE.h:36
bool useJsonBody
Whether requests against the token and refresh endpoints should use a JSON body to the POST request.
Definition OAuth2PKCE.h:65
std::optional< int > redirectPort
The port that the internal HTTP server will listen on.
Definition OAuth2PKCE.h:57
std::string clientID
The OAuth2 client ID.
Definition OAuth2PKCE.h:40
std::string redirectPath
The URL path that will be used to create the redirect URI.
Definition OAuth2PKCE.h:49
Tokens obtained from a successful OAuth2 authentication operation.
Definition OAuth2PKCE.h:18
std::string accessToken
The access token returned. This can be used to authenticate requests.
Definition OAuth2PKCE.h:23
std::optional< std::string > refreshToken
The refresh token returned, if any.
Definition OAuth2PKCE.h:30