-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for trust grants that can issue tokens for any subj…
…ect (#3012) Previously, a trust relationship had to be setup for every subject before the issuer could sign a JWT token for it. This change will allow setting up token services that can issue tokens with any value in the subject field. Closes #2930 Co-authored-by: aeneasr <[email protected]>
- Loading branch information
1 parent
05286df
commit a3c4304
Showing
27 changed files
with
577 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,9 +6,9 @@ dayjs.extend(isBetween) | |
|
||
describe('The JWT-Bearer Grants Admin Interface', () => { | ||
let d = dayjs().utc().add(1, 'year').set('millisecond', 0) | ||
const newGrant = (issuer = 'token-service', subject = '[email protected]') => ({ | ||
issuer, | ||
subject, | ||
const newGrant = () => ({ | ||
issuer: 'token-service', | ||
subject: '[email protected]', | ||
expires_at: d.toISOString(), | ||
scope: ['openid', 'offline'], | ||
jwk: { | ||
|
@@ -119,4 +119,56 @@ describe('The JWT-Bearer Grants Admin Interface', () => { | |
expect(response.status).to.equal(400) | ||
}) | ||
}) | ||
|
||
it('should fail, because trying to create grant with no subject and no allow_any_subject flag', () => { | ||
const grant = newGrant() | ||
delete grant.subject | ||
delete grant.allow_any_subject | ||
cy.request({ | ||
method: 'POST', | ||
url: Cypress.env('admin_url') + '/trust/grants/jwt-bearer/issuers', | ||
failOnStatusCode: false, | ||
body: JSON.stringify(grant) | ||
}).then((response) => { | ||
expect(response.status).to.equal(400) | ||
}) | ||
}) | ||
|
||
it('should return newly created jwt-bearer grant when issuer is allowed to authorize any subject', () => { | ||
const grant = newGrant() | ||
delete grant.subject | ||
grant.allow_any_subject = true | ||
const start = dayjs().subtract(1, 'minutes') | ||
const end = dayjs().add(1, 'minutes') | ||
cy.request( | ||
'POST', | ||
Cypress.env('admin_url') + '/trust/grants/jwt-bearer/issuers', | ||
JSON.stringify(grant) | ||
).then((response) => { | ||
const createdAt = dayjs(response.body.created_at) | ||
const expiresAt = dayjs(response.body.expires_at) | ||
const grantID = response.body.id | ||
|
||
expect(response.body.allow_any_subject).to.equal(grant.allow_any_subject) | ||
expect(response.body.issuer).to.equal(grant.issuer) | ||
expect(createdAt.isBetween(start, end)).to.true | ||
expect(expiresAt.isSame(grant.expires_at)).to.true | ||
expect(response.body.scope).to.deep.equal(grant.scope) | ||
expect(response.body.public_key.set).to.equal(grant.issuer) | ||
expect(response.body.public_key.kid).to.equal(grant.jwk.kid) | ||
|
||
cy.request( | ||
'GET', | ||
Cypress.env('admin_url') + '/trust/grants/jwt-bearer/issuers/' + grantID | ||
).then((response) => { | ||
expect(response.body.allow_any_subject).to.equal( | ||
grant.allow_any_subject | ||
) | ||
expect(response.body.issuer).to.equal(grant.issuer) | ||
expect(response.body.scope).to.deep.equal(grant.scope) | ||
expect(response.body.public_key.set).to.equal(grant.issuer) | ||
expect(response.body.public_key.kid).to.equal(grant.jwk.kid) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1971,7 +1971,7 @@ import ( | |
) | ||
|
||
func main() { | ||
trustJwtGrantIssuerBody := *openapiclient.NewTrustJwtGrantIssuerBody(time.Now(), "https://jwt-idp.example.com", *openapiclient.NewJSONWebKey("RS256", "1603dfe0af8f4596", "RSA", "sig"), []string{"Scope_example"}, "[email protected]") // TrustJwtGrantIssuerBody | (optional) | ||
trustJwtGrantIssuerBody := *openapiclient.NewTrustJwtGrantIssuerBody(time.Now(), "https://jwt-idp.example.com", *openapiclient.NewJSONWebKey("RS256", "1603dfe0af8f4596", "RSA", "sig"), []string{"Scope_example"}) // TrustJwtGrantIssuerBody | (optional) | ||
|
||
configuration := openapiclient.NewConfiguration() | ||
apiClient := openapiclient.NewAPIClient(configuration) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.