Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add auth config to oauth api #7798

Merged
merged 8 commits into from
Nov 15, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions airbyte-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ task generateApiServer(type: GenerateTask) {
modelPackage = "io.airbyte.api.model"

importMappings = [
'AuthConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
'SourceDefinitionSpecification' : 'com.fasterxml.jackson.databind.JsonNode',
'SourceConfiguration' : 'com.fasterxml.jackson.databind.JsonNode',
'DestinationDefinitionSpecification': 'com.fasterxml.jackson.databind.JsonNode',
Expand Down
31 changes: 27 additions & 4 deletions airbyte-api/src/main/openapi/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/CompleteOauthResponse"
$ref: "#/components/schemas/CompleteSourceOauthResponse"
"404":
$ref: "#/components/responses/NotFoundResponse"
"422":
Expand Down Expand Up @@ -1357,7 +1357,7 @@ paths:
content:
application/json:
schema:
$ref: "#/components/schemas/CompleteOauthResponse"
$ref: "#/components/schemas/CompleteDestinationOauthResponse"
"404":
$ref: "#/components/responses/NotFoundResponse"
"422":
Expand Down Expand Up @@ -3227,6 +3227,8 @@ components:
items:
$ref: "#/components/schemas/DbMigrationRead"
# OAuth
AuthConfiguration:
description: The values required to configure OAuth flows. The schema for this must match the authSpecification schema.
SourceOauthConsentRequest:
type: object
required:
Expand All @@ -3241,6 +3243,8 @@ components:
redirectUrl:
description: The url to redirect to after getting the user consent
type: string
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
DestinationOauthConsentRequest:
type: object
required:
Expand All @@ -3255,6 +3259,8 @@ components:
redirectUrl:
description: The url to redirect to after getting the user consent
type: string
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
OAuthConsentRead:
type: object
required:
Expand All @@ -3279,6 +3285,8 @@ components:
description: The query parameters present in the redirect URL after a user granted consent e.g auth code
type: object
additionalProperties: true # Oauth parameters like code, state, etc.. will be different per API so we don't specify them in advance
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
CompleteDestinationOAuthRequest:
type: object
required:
Expand All @@ -3296,9 +3304,24 @@ components:
description: The query parameters present in the redirect URL after a user granted consent e.g auth code
type: object
additionalProperties: true # Oauth parameters like code, state, etc.. will be different per API so we don't specify them in advance
CompleteOauthResponse:
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
CompleteSourceOauthResponse:
type: object
additionalProperties: true # Oauth parameters like refresh/access token etc.. will be different per API so we don't specify them in advance
properties:
oauthOutput:
type: object
additionalProperties: true # Oauth parameters like refresh/access token etc.. will be different per API so we don't specify them in advance
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
CompleteDestinationOauthResponse:
type: object
properties:
oauthOutput:
type: object
additionalProperties: true # Oauth parameters like refresh/access token etc.. will be different per API so we don't specify them in advance
authConfiguration:
$ref: "#/components/schemas/AuthConfiguration"
SetInstancewideSourceOauthParamsRequestBody:
type: object
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
import io.airbyte.api.model.CheckConnectionRead;
import io.airbyte.api.model.CheckOperationRead;
import io.airbyte.api.model.CompleteDestinationOAuthRequest;
import io.airbyte.api.model.CompleteDestinationOauthResponse;
import io.airbyte.api.model.CompleteSourceOauthRequest;
import io.airbyte.api.model.CompleteSourceOauthResponse;
import io.airbyte.api.model.ConnectionCreate;
import io.airbyte.api.model.ConnectionIdRequestBody;
import io.airbyte.api.model.ConnectionRead;
Expand Down Expand Up @@ -122,7 +124,6 @@
import java.io.IOException;
import java.net.http.HttpClient;
import java.nio.file.Path;
import java.util.Map;

@javax.ws.rs.Path("/v1")
public class ConfigurationApi implements io.airbyte.api.V1Api {
Expand Down Expand Up @@ -300,7 +301,7 @@ public OAuthConsentRead getSourceOAuthConsent(final SourceOauthConsentRequest so
}

@Override
public Map<String, Object> completeSourceOAuth(final CompleteSourceOauthRequest completeSourceOauthRequest) {
public CompleteSourceOauthResponse completeSourceOAuth(final CompleteSourceOauthRequest completeSourceOauthRequest) {
return execute(() -> oAuthHandler.completeSourceOAuth(completeSourceOauthRequest));
}

Expand All @@ -310,7 +311,7 @@ public OAuthConsentRead getDestinationOAuthConsent(final DestinationOauthConsent
}

@Override
public Map<String, Object> completeDestinationOAuth(final CompleteDestinationOAuthRequest requestBody) {
public CompleteDestinationOauthResponse completeDestinationOAuth(final CompleteDestinationOAuthRequest requestBody) {
return execute(() -> oAuthHandler.completeDestinationOAuth(requestBody));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import com.google.common.collect.ImmutableMap;
import io.airbyte.analytics.TrackingClient;
import io.airbyte.api.model.CompleteDestinationOAuthRequest;
import io.airbyte.api.model.CompleteDestinationOauthResponse;
import io.airbyte.api.model.CompleteSourceOauthRequest;
import io.airbyte.api.model.CompleteSourceOauthResponse;
import io.airbyte.api.model.DestinationOauthConsentRequest;
import io.airbyte.api.model.OAuthConsentRead;
import io.airbyte.api.model.SetInstancewideDestinationOauthParamsRequestBody;
Expand All @@ -26,7 +28,6 @@
import io.airbyte.validation.json.JsonValidationException;
import java.io.IOException;
import java.net.http.HttpClient;
import java.util.Map;
import java.util.UUID;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -83,17 +84,18 @@ public OAuthConsentRead getDestinationOAuthConsent(final DestinationOauthConsent
return result;
}

public Map<String, Object> completeSourceOAuth(final CompleteSourceOauthRequest oauthSourceRequestBody)
public CompleteSourceOauthResponse completeSourceOAuth(final CompleteSourceOauthRequest oauthSourceRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardSourceDefinition sourceDefinition = configRepository.getStandardSourceDefinition(oauthSourceRequestBody.getSourceDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation =
oAuthImplementationFactory.create(sourceDefinition, oauthSourceRequestBody.getWorkspaceId());
final ImmutableMap<String, Object> metadata = generateSourceMetadata(oauthSourceRequestBody.getSourceDefinitionId());
final Map<String, Object> result = oAuthFlowImplementation.completeSourceOAuth(
final CompleteSourceOauthResponse result = new CompleteSourceOauthResponse();
result.oauthOutput(oAuthFlowImplementation.completeSourceOAuth(
oauthSourceRequestBody.getWorkspaceId(),
oauthSourceRequestBody.getSourceDefinitionId(),
oauthSourceRequestBody.getQueryParams(),
oauthSourceRequestBody.getRedirectUrl());
oauthSourceRequestBody.getRedirectUrl()));
try {
trackingClient.track(oauthSourceRequestBody.getWorkspaceId(), "Complete OAuth Flow - Backend", metadata);
} catch (final Exception e) {
Expand All @@ -102,18 +104,19 @@ public Map<String, Object> completeSourceOAuth(final CompleteSourceOauthRequest
return result;
}

public Map<String, Object> completeDestinationOAuth(final CompleteDestinationOAuthRequest oauthDestinationRequestBody)
public CompleteDestinationOauthResponse completeDestinationOAuth(final CompleteDestinationOAuthRequest oauthDestinationRequestBody)
throws JsonValidationException, ConfigNotFoundException, IOException {
final StandardDestinationDefinition destinationDefinition =
configRepository.getStandardDestinationDefinition(oauthDestinationRequestBody.getDestinationDefinitionId());
final OAuthFlowImplementation oAuthFlowImplementation =
oAuthImplementationFactory.create(destinationDefinition, oauthDestinationRequestBody.getWorkspaceId());
final ImmutableMap<String, Object> metadata = generateDestinationMetadata(oauthDestinationRequestBody.getDestinationDefinitionId());
final Map<String, Object> result = oAuthFlowImplementation.completeDestinationOAuth(
final CompleteDestinationOauthResponse result = new CompleteDestinationOauthResponse();
result.oauthOutput(oAuthFlowImplementation.completeDestinationOAuth(
oauthDestinationRequestBody.getWorkspaceId(),
oauthDestinationRequestBody.getDestinationDefinitionId(),
oauthDestinationRequestBody.getQueryParams(),
oauthDestinationRequestBody.getRedirectUrl());
oauthDestinationRequestBody.getRedirectUrl()));
try {
trackingClient.track(oauthDestinationRequestBody.getWorkspaceId(), "Complete OAuth Flow - Backend", metadata);
} catch (final Exception e) {
Expand Down
46 changes: 42 additions & 4 deletions docs/reference/api/generated-api-html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3032,12 +3032,20 @@ <h3 class="field-label">Request body</h3>

<h3 class="field-label">Return type</h3>
<div class="return-type">
<a href="#CompleteDestinationOauthResponse">CompleteDestinationOauthResponse</a>

map[String, Object]
</div>

<!--Todo: process Response Object and its headers, schema, examples -->

<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"oauthOutput" : {
"key" : "{}"
},
"authConfiguration" : ""
}</code></pre>

<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
Expand All @@ -3049,7 +3057,7 @@ <h3 class="field-label">Produces</h3>
<h3 class="field-label">Responses</h3>
<h4 class="field-label">200</h4>
Successful operation
<a href="#map[String, Object]">map[String, Object]</a>
<a href="#CompleteDestinationOauthResponse">CompleteDestinationOauthResponse</a>
<h4 class="field-label">404</h4>
Object with given id was not found.
<a href="#NotFoundKnownExceptionInfo">NotFoundKnownExceptionInfo</a>
Expand Down Expand Up @@ -3085,12 +3093,20 @@ <h3 class="field-label">Request body</h3>

<h3 class="field-label">Return type</h3>
<div class="return-type">
<a href="#CompleteSourceOauthResponse">CompleteSourceOauthResponse</a>

map[String, Object]
</div>

<!--Todo: process Response Object and its headers, schema, examples -->

<h3 class="field-label">Example data</h3>
<div class="example-data-content-type">Content-Type: application/json</div>
<pre class="example"><code>{
"oauthOutput" : {
"key" : "{}"
},
"authConfiguration" : ""
}</code></pre>

<h3 class="field-label">Produces</h3>
This API call produces the following media types according to the <span class="header">Accept</span> request header;
Expand All @@ -3102,7 +3118,7 @@ <h3 class="field-label">Produces</h3>
<h3 class="field-label">Responses</h3>
<h4 class="field-label">200</h4>
Successful operation
<a href="#map[String, Object]">map[String, Object]</a>
<a href="#CompleteSourceOauthResponse">CompleteSourceOauthResponse</a>
<h4 class="field-label">404</h4>
Object with given id was not found.
<a href="#NotFoundKnownExceptionInfo">NotFoundKnownExceptionInfo</a>
Expand Down Expand Up @@ -6594,7 +6610,9 @@ <h3>Table of Contents</h3>
<li><a href="#CheckConnectionRead"><code>CheckConnectionRead</code> - </a></li>
<li><a href="#CheckOperationRead"><code>CheckOperationRead</code> - </a></li>
<li><a href="#CompleteDestinationOAuthRequest"><code>CompleteDestinationOAuthRequest</code> - </a></li>
<li><a href="#CompleteDestinationOauthResponse"><code>CompleteDestinationOauthResponse</code> - </a></li>
<li><a href="#CompleteSourceOauthRequest"><code>CompleteSourceOauthRequest</code> - </a></li>
<li><a href="#CompleteSourceOauthResponse"><code>CompleteSourceOauthResponse</code> - </a></li>
<li><a href="#ConnectionCreate"><code>ConnectionCreate</code> - </a></li>
<li><a href="#ConnectionIdRequestBody"><code>ConnectionIdRequestBody</code> - </a></li>
<li><a href="#ConnectionRead"><code>ConnectionRead</code> - </a></li>
Expand Down Expand Up @@ -6802,6 +6820,15 @@ <h3><a name="CompleteDestinationOAuthRequest"><code>CompleteDestinationOAuthRequ
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">redirectUrl (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> When completing OAuth flow to gain an access token, some API sometimes requires to verify that the app re-send the redirectUrl that was used when consent was given. </div>
<div class="param">queryParams (optional)</div><div class="param-desc"><span class="param-type"><a href="#object">map[String, Object]</a></span> The query parameters present in the redirect URL after a user granted consent e.g auth code </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="CompleteDestinationOauthResponse"><code>CompleteDestinationOauthResponse</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">oauthOutput (optional)</div><div class="param-desc"><span class="param-type"><a href="#object">map[String, Object]</a></span> </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand All @@ -6812,6 +6839,15 @@ <h3><a name="CompleteSourceOauthRequest"><code>CompleteSourceOauthRequest</code>
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">redirectUrl (optional)</div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> When completing OAuth flow to gain an access token, some API sometimes requires to verify that the app re-send the redirectUrl that was used when consent was given. </div>
<div class="param">queryParams (optional)</div><div class="param-desc"><span class="param-type"><a href="#object">map[String, Object]</a></span> The query parameters present in the redirect URL after a user granted consent e.g auth code </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
<h3><a name="CompleteSourceOauthResponse"><code>CompleteSourceOauthResponse</code> - </a> <a class="up" href="#__Models">Up</a></h3>
<div class='model-description'></div>
<div class="field-items">
<div class="param">oauthOutput (optional)</div><div class="param-desc"><span class="param-type"><a href="#object">map[String, Object]</a></span> </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down Expand Up @@ -7058,6 +7094,7 @@ <h3><a name="DestinationOauthConsentRequest"><code>DestinationOauthConsentReques
<div class="param">destinationDefinitionId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">redirectUrl </div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> The url to redirect to after getting the user consent </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down Expand Up @@ -7526,6 +7563,7 @@ <h3><a name="SourceOauthConsentRequest"><code>SourceOauthConsentRequest</code> -
<div class="param">sourceDefinitionId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">workspaceId </div><div class="param-desc"><span class="param-type"><a href="#UUID">UUID</a></span> format: uuid</div>
<div class="param">redirectUrl </div><div class="param-desc"><span class="param-type"><a href="#string">String</a></span> The url to redirect to after getting the user consent </div>
<div class="param">authConfiguration (optional)</div><div class="param-desc"><span class="param-type"><a href="#">oas_any_type_not_mapped</a></span> The values required to configure OAuth flows. The schema for this must match the authSpecification schema. </div>
</div> <!-- field-items -->
</div>
<div class="model">
Expand Down