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

fix(httpRequest): naming clash, update nimbus sdk to latest #576

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 49 additions & 0 deletions .github/workflows/test-dp-pr.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Test PR
on:
pull_request_target:
paths-ignore:
- '*.md'

permissions:
pull-requests: write
contents: write

jobs:
test_dp_pr:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Checkout latest code
uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'zulu'
cache: 'gradle'

- name: Build with Gradle
run: ./gradlew build

dependabot_pr:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
needs: test_dp_pr
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enable auto-merge for Dependabot PRs
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28 changes: 1 addition & 27 deletions .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
name: Test PR
on:
pull_request_target:
pull_request:
paths-ignore:
- '*.md'

permissions:
pull-requests: write
contents: write

jobs:
test_pr:
runs-on: ubuntu-latest
Expand All @@ -24,25 +20,3 @@ jobs:

- name: Build with Gradle
run: ./gradlew build

dependabot_pr:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
needs: test_pr
steps:
- name: Dependabot metadata
id: dependabot-metadata
uses: dependabot/fetch-metadata@v1.6.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Approve a PR
run: gh pr review --approve "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Enable auto-merge for Dependabot PRs
if: ${{ steps.dependabot-metadata.outputs.update-type != 'version-update:semver-major' }}
run: gh pr merge --auto --squash "$PR_URL"
env:
PR_URL: ${{ github.event.pull_request.html_url }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ data class OAuth2HttpRequest(

@Suppress("MemberVisibilityCanBePrivate")
fun asNimbusHTTPRequest(): HTTPRequest {
val inputBody = body
return HTTPRequest(HTTPRequest.Method.valueOf(method), url.toUrl())
.apply {
headers.forEach { header -> this.setHeader(header.first, header.second) }
query = body
body = inputBody
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,33 +91,38 @@ class TokenExchangeGrantIntegrationTest {
fun `token request with token exchange grant and client basic auth should exchange subject_token with a new token containing many of the same claims`() {
withMockOAuth2Server {
val initialSubject = "yolo"
val initialToken = this.issueToken(
issuerId = "idprovider",
clientId = "initialClient",
tokenCallback = DefaultOAuth2TokenCallback(
val initialToken =
this.issueToken(
issuerId = "idprovider",
subject = initialSubject,
claims = mapOf(
"claim1" to "value1",
"claim2" to "value2",
),
),
)
clientId = "initialClient",
tokenCallback =
DefaultOAuth2TokenCallback(
issuerId = "idprovider",
subject = initialSubject,
claims =
mapOf(
"claim1" to "value1",
"claim2" to "value2",
),
),
)

val issuerId = "tokenx"
val tokenEndpointUrl = this.tokenEndpointUrl(issuerId)
val targetAudienceForToken = "targetAudience"

val response: ParsedTokenResponse = client.tokenRequest(
url = tokenEndpointUrl,
basicAuth = Pair("client", "secret"),
parameters = mapOf(
"grant_type" to TOKEN_EXCHANGE.value,
"subject_token_type" to SubjectTokenType.TOKEN_TYPE_JWT,
"subject_token" to initialToken.serialize(),
"audience" to targetAudienceForToken,
),
).toTokenResponse()
val response: ParsedTokenResponse =
client.tokenRequest(
url = tokenEndpointUrl,
basicAuth = Pair("client", "secret"),
parameters =
mapOf(
"grant_type" to TOKEN_EXCHANGE.value,
"subject_token_type" to SubjectTokenType.TOKEN_TYPE_JWT,
"subject_token" to initialToken.serialize(),
"audience" to targetAudienceForToken,
),
).toTokenResponse()

response shouldBeValidFor TOKEN_EXCHANGE
response.scope shouldBe null
Expand All @@ -136,17 +141,17 @@ class TokenExchangeGrantIntegrationTest {
@Test
fun `token request without client_assertion should fail`() {
withMockOAuth2Server {
val response: Response =
val response: Response =
client.tokenRequest(
url = this.tokenEndpointUrl("tokenx"),
parameters =
mapOf(
"grant_type" to TOKEN_EXCHANGE.value,
"subject_token_type" to SubjectTokenType.TOKEN_TYPE_JWT,
"subject_token" to "yolo",
"audience" to "targetAudienceForToken",
),
)
url = this.tokenEndpointUrl("tokenx"),
parameters =
mapOf(
"grant_type" to TOKEN_EXCHANGE.value,
"subject_token_type" to SubjectTokenType.TOKEN_TYPE_JWT,
"subject_token" to "yolo",
"audience" to "targetAudienceForToken",
),
)
response.code shouldBe 400
}
}
Expand Down
Loading