Skip to content

Commit 0d0773d

Browse files
authored
SWI-8856 Add OAuth (#209)
* update generator version * add oauth * updates to oauth * more oauth fixes * update bw yaml * update SDK * generator version * clean files * no java 25 * restore files * update org.json dep * update deps * update templates and test * update tests to use new client id and secret * add env vars to wf files * update readme
1 parent 7b87e95 commit 0d0773d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1606
-544
lines changed

.github/workflows/deploy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }}
1313
BW_USERNAME: ${{ secrets.BW_USERNAME }}
1414
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
15+
BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }}
16+
BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }}
1517
BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }}
1618
BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }}
1719
BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }}

.github/workflows/test-pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ env:
1414
BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }}
1515
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
1616
BW_USERNAME: ${{ secrets.BW_USERNAME }}
17+
BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }}
18+
BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }}
1719
BW_VOICE_APPLICATION_ID: ${{ secrets.BW_VOICE_APPLICATION_ID }}
1820
BW_MESSAGING_APPLICATION_ID: ${{ secrets.BW_MESSAGING_APPLICATION_ID }}
1921
BW_NUMBER: ${{ secrets.BW_NUMBER }}

.github/workflows/test-smoke.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ concurrency:
1515
env:
1616
BW_USERNAME: ${{ secrets.BW_USERNAME }}
1717
BW_PASSWORD: ${{ secrets.BW_PASSWORD }}
18+
BW_ACCOUNT_ID: ${{ secrets.BW_ACCOUNT_ID }}
19+
BW_CLIENT_ID: ${{ secrets.BW_CLIENT_ID }}
20+
BW_CLIENT_SECRET: ${{ secrets.BW_CLIENT_SECRET }}
1821
BW_USERNAME_FORBIDDEN: ${{ secrets.BW_USERNAME_FORBIDDEN }}
1922
BW_PASSWORD_FORBIDDEN: ${{ secrets.BW_PASSWORD_FORBIDDEN }}
2023
USER_NUMBER: ${{ secrets.USER_NUMBER }}

.openapi-generator/FILES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ src/main/java/com/bandwidth/sdk/auth/ApiKeyAuth.java
225225
src/main/java/com/bandwidth/sdk/auth/Authentication.java
226226
src/main/java/com/bandwidth/sdk/auth/HttpBasicAuth.java
227227
src/main/java/com/bandwidth/sdk/auth/HttpBearerAuth.java
228+
src/main/java/com/bandwidth/sdk/auth/OAuth.java
229+
src/main/java/com/bandwidth/sdk/auth/OAuthFlow.java
230+
src/main/java/com/bandwidth/sdk/auth/OAuthOkHttpClient.java
231+
src/main/java/com/bandwidth/sdk/auth/RetryingOAuth.java
228232
src/main/java/com/bandwidth/sdk/model/AbstractOpenApiSchema.java
229233
src/main/java/com/bandwidth/sdk/model/AccountStatistics.java
230234
src/main/java/com/bandwidth/sdk/model/AdditionalDenialReason.java

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ public class Example {
9898
Basic.setUsername("YOUR USERNAME");
9999
Basic.setPassword("YOUR PASSWORD");
100100

101+
// Configure OAuth2 access token for authorization: OAuth2
102+
OAuth OAuth2 = (OAuth) defaultClient.getAuthentication("OAuth2");
103+
OAuth2.setAccessToken("YOUR ACCESS TOKEN");
104+
101105
CallsApi apiInstance = new CallsApi(defaultClient);
106+
// Or create the instance with a your clientId and clientSecret (for OAuth2):
107+
// CallsApi apiInstance = new CallsApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET", null);
108+
102109
String accountId = "9900000"; // String | Your Bandwidth Account ID.
103110
CreateCall createCall = new CreateCall(); // CreateCall | JSON object containing information to create an outbound call
104111
try {
@@ -362,6 +369,14 @@ Authentication schemes defined for the API:
362369

363370
- **Type**: HTTP basic authentication
364371

372+
<a id="OAuth2"></a>
373+
### OAuth2
374+
375+
- **Type**: OAuth
376+
- **Flow**: application
377+
- **Authorization URL**:
378+
- **Scopes**: N/A
379+
365380

366381
## Recommendation
367382

api/openapi.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ servers:
1111
- url: /
1212
security:
1313
- Basic: []
14+
- OAuth2: []
1415
tags:
1516
- name: Messages
1617
- name: Media
@@ -14925,4 +14926,10 @@ components:
1492514926
- Example: `Authorization: Basic ZGVtbZpwQDU1dzByZA==`
1492614927
scheme: basic
1492714928
type: http
14929+
OAuth2:
14930+
flows:
14931+
clientCredentials:
14932+
scopes: {}
14933+
tokenUrl: https://api.bandwidth.com/api/v1/oauth2/token
14934+
type: oauth2
1492814935

bandwidth.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ info:
99
version: 1.0.0
1010
security:
1111
- Basic: []
12+
- OAuth2: []
1213
tags:
1314
- name: Messages
1415
- name: Media
@@ -8427,6 +8428,12 @@ components:
84278428
84288429
84298430
- Example: `Authorization: Basic ZGVtbZpwQDU1dzByZA==`
8431+
OAuth2:
8432+
type: oauth2
8433+
flows:
8434+
clientCredentials:
8435+
tokenUrl: https://api.bandwidth.com/api/v1/oauth2/token
8436+
scopes: {}
84308437
callbacks:
84318438
inboundCallback:
84328439
'{inboundCallbackUrl}':

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ dependencies {
113113
implementation 'io.gsonfire:gson-fire:1.9.0'
114114
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
115115
implementation 'org.openapitools:jackson-databind-nullable:0.2.8'
116+
implementation group: 'org.json', name: 'json', version: '20250517'
117+
implementation group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.2'
116118
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.18.0'
117119
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
118120
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'

build.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ lazy val root = (project in file(".")).
1616
"org.apache.commons" % "commons-lang3" % "3.18.0",
1717
"jakarta.ws.rs" % "jakarta.ws.rs-api" % "2.1.6",
1818
"org.openapitools" % "jackson-databind-nullable" % "0.2.8",
19+
"org.json" % "json" % "20250517",
20+
"org.apache.oltu.oauth2" % "org.apache.oltu.oauth2.client" % "1.0.2",
1921
"io.gsonfire" % "gson-fire" % "1.9.0" % "compile",
2022
"jakarta.annotation" % "jakarta.annotation-api" % "1.3.5" % "compile",
2123
"com.google.code.findbugs" % "jsr305" % "3.0.2" % "compile",
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
apply plugin: 'idea'
2+
apply plugin: 'eclipse'
3+
{{#sourceFolder}}
4+
apply plugin: 'java'
5+
{{/sourceFolder}}
6+
apply plugin: 'com.diffplug.spotless'
7+
8+
group = '{{groupId}}'
9+
version = '{{artifactVersion}}'
10+
11+
buildscript {
12+
repositories {
13+
mavenCentral()
14+
}
15+
dependencies {
16+
classpath 'com.android.tools.build:gradle:2.3.+'
17+
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
18+
classpath 'com.diffplug.spotless:spotless-plugin-gradle:6.11.0'
19+
}
20+
}
21+
22+
repositories {
23+
mavenCentral()
24+
}
25+
{{#sourceFolder}}
26+
sourceSets {
27+
main.java.srcDirs = ['{{sourceFolder}}']
28+
}
29+
30+
{{/sourceFolder}}
31+
if(hasProperty('target') && target == 'android') {
32+
33+
apply plugin: 'com.android.library'
34+
apply plugin: 'com.github.dcendents.android-maven'
35+
36+
android {
37+
compileSdkVersion 25
38+
buildToolsVersion '25.0.2'
39+
defaultConfig {
40+
minSdkVersion 14
41+
targetSdkVersion 25
42+
}
43+
compileOptions {
44+
sourceCompatibility JavaVersion.VERSION_1_8
45+
targetCompatibility JavaVersion.VERSION_1_8
46+
}
47+
48+
// Rename the aar correctly
49+
libraryVariants.all { variant ->
50+
variant.outputs.each { output ->
51+
def outputFile = output.outputFile
52+
if (outputFile != null && outputFile.name.endsWith('.aar')) {
53+
def fileName = "${project.name}-${variant.baseName}-${version}.aar"
54+
output.outputFile = new File(outputFile.parent, fileName)
55+
}
56+
}
57+
}
58+
59+
dependencies {
60+
provided "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
61+
}
62+
}
63+
64+
afterEvaluate {
65+
android.libraryVariants.all { variant ->
66+
def task = project.tasks.create "jar${variant.name.capitalize()}", Jar
67+
task.description = "Create jar artifact for ${variant.name}"
68+
task.dependsOn variant.javaCompile
69+
task.from variant.javaCompile.destinationDirectory
70+
task.destinationDirectory = project.file("${project.buildDir}/outputs/jar")
71+
task.archiveFileName = "${project.name}-${variant.baseName}-${version}.jar"
72+
artifacts.add('archives', task)
73+
}
74+
}
75+
76+
task sourcesJar(type: Jar) {
77+
from android.sourceSets.main.java.srcDirs
78+
classifier = 'sources'
79+
}
80+
81+
artifacts {
82+
archives sourcesJar
83+
}
84+
85+
} else {
86+
87+
apply plugin: 'java'
88+
apply plugin: 'maven-publish'
89+
90+
sourceCompatibility = JavaVersion.VERSION_1_8
91+
targetCompatibility = JavaVersion.VERSION_1_8
92+
93+
publishing {
94+
publications {
95+
maven(MavenPublication) {
96+
artifactId = '{{artifactId}}'
97+
from components.java
98+
}
99+
}
100+
}
101+
102+
task execute(type:JavaExec) {
103+
main = System.getProperty('mainClass')
104+
classpath = sourceSets.main.runtimeClasspath
105+
}
106+
}
107+
108+
ext {
109+
{{#swagger1AnnotationLibrary}}
110+
swagger_annotations_version = "1.6.9"
111+
{{/swagger1AnnotationLibrary}}
112+
{{#swagger2AnnotationLibrary}}
113+
swagger_annotations_version = "2.2.9"
114+
{{/swagger2AnnotationLibrary}}
115+
jakarta_annotation_version = "1.3.5"
116+
{{#useBeanValidation}}
117+
bean_validation_version = "2.0.2"
118+
{{/useBeanValidation}}
119+
}
120+
121+
dependencies {
122+
{{#swagger1AnnotationLibrary}}
123+
implementation "io.swagger:swagger-annotations:$swagger_annotations_version"
124+
{{/swagger1AnnotationLibrary}}
125+
{{#swagger2AnnotationLibrary}}
126+
implementation "io.swagger.core.v3:swagger-annotations:$swagger_annotations_version"
127+
{{/swagger2AnnotationLibrary}}
128+
implementation "com.google.code.findbugs:jsr305:3.0.2"
129+
implementation 'com.squareup.okhttp3:okhttp:4.12.0'
130+
implementation 'com.squareup.okhttp3:logging-interceptor:4.12.0'
131+
implementation 'com.google.code.gson:gson:2.9.1'
132+
implementation 'io.gsonfire:gson-fire:1.9.0'
133+
implementation 'jakarta.ws.rs:jakarta.ws.rs-api:2.1.6'
134+
{{#openApiNullable}}
135+
implementation 'org.openapitools:jackson-databind-nullable:0.2.8'
136+
{{/openApiNullable}}
137+
{{#withAWSV4Signature}}
138+
implementation 'software.amazon.awssdk:auth:2.20.157'
139+
{{/withAWSV4Signature}}
140+
{{#hasOAuthMethods}}
141+
implementation group: 'org.json', name: 'json', version: '20250517'
142+
implementation group: 'org.apache.oltu.oauth2', name: 'org.apache.oltu.oauth2.client', version: '1.0.2'
143+
{{/hasOAuthMethods}}
144+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.18.0'
145+
{{#joda}}
146+
implementation 'joda-time:joda-time:2.9.9'
147+
{{/joda}}
148+
{{#dynamicOperations}}
149+
implementation 'io.swagger.parser.v3:swagger-parser-v3:2.0.30'
150+
{{/dynamicOperations}}
151+
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
152+
{{#useBeanValidation}}
153+
implementation "jakarta.validation:jakarta.validation-api:$bean_validation_version"
154+
{{/useBeanValidation}}
155+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.10.3'
156+
testImplementation 'org.mockito:mockito-core:3.12.4'
157+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.10.3'
158+
}
159+
160+
javadoc {
161+
options.tags = [ "http.response.details:a:Http Response Details" ]
162+
}
163+
164+
// Use spotless plugin to automatically format code, remove unused import, etc
165+
// To apply changes directly to the file, run `gradlew spotlessApply`
166+
// Ref: https://github.com/diffplug/spotless/tree/main/plugin-gradle
167+
spotless {
168+
// comment out below to run spotless as part of the `check` task
169+
enforceCheck false
170+
171+
format 'misc', {
172+
// define the files (e.g. '*.gradle', '*.md') to apply `misc` to
173+
target '.gitignore'
174+
175+
// define the steps to apply to those files
176+
trimTrailingWhitespace()
177+
indentWithSpaces() // Takes an integer argument if you don't like 4
178+
endWithNewline()
179+
}
180+
java {
181+
// don't need to set target, it is inferred from java
182+
183+
// apply a specific flavor of google-java-format
184+
googleJavaFormat('1.8').aosp().reflowLongStrings()
185+
186+
removeUnusedImports()
187+
importOrder()
188+
}
189+
}
190+
191+
test {
192+
// Enable JUnit 5 (Gradle 4.6+).
193+
useJUnitPlatform()
194+
195+
// Always run tests, even when nothing changed.
196+
dependsOn 'cleanTest'
197+
198+
// Show test results.
199+
testLogging {
200+
events "passed", "skipped", "failed"
201+
}
202+
203+
}

0 commit comments

Comments
 (0)