Skip to content
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
16 changes: 16 additions & 0 deletions lib/workos/user_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,22 @@ def revoke_invitation(id:)
WorkOS::Invitation.new(response.body)
end

# Resends an existing Invitation.
#
# @param [String] id The unique ID of the Invitation.
#
# @return WorkOS::Invitation
def resend_invitation(id:)
request = post_request(
path: "/user_management/invitations/#{id}/resend",
auth: true,
)

response = execute_request(request: request)

WorkOS::Invitation.new(response.body)
end

private

def validate_session(session)
Expand Down
75 changes: 75 additions & 0 deletions spec/lib/workos/user_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1693,6 +1693,81 @@
end
end

describe '.resend_invitation' do
context 'with valid payload' do
it 'resends invitation' do
VCR.use_cassette 'user_management/resend_invitation/valid' do
invitation = described_class.resend_invitation(
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
)

expect(invitation.id).to eq('invitation_01H5JQDV7R7ATEYZDEG0W5PRYS')
expect(invitation.email).to eq('[email protected]')
end
end
end

context 'with an invalid id' do
it 'returns an error' do
VCR.use_cassette 'user_management/resend_invitation/invalid' do
expect do
described_class.resend_invitation(
id: 'invalid_id',
)
end.to raise_error(
WorkOS::NotFoundError,
/Invitation not found/,
)
end
end
end

context 'when invitation has expired' do
it 'returns an error' do
VCR.use_cassette 'user_management/resend_invitation/expired' do
expect do
described_class.resend_invitation(
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
)
end.to raise_error(
WorkOS::InvalidRequestError,
/Invite has expired/,
)
end
end
end

context 'when invitation has been revoked' do
it 'returns an error' do
VCR.use_cassette 'user_management/resend_invitation/revoked' do
expect do
described_class.resend_invitation(
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
)
end.to raise_error(
WorkOS::InvalidRequestError,
/Invite has been revoked/,
)
end
end
end

context 'when invitation has already been accepted' do
it 'returns an error' do
VCR.use_cassette 'user_management/resend_invitation/accepted' do
expect do
described_class.resend_invitation(
id: 'invitation_01H5JQDV7R7ATEYZDEG0W5PRYS',
)
end.to raise_error(
WorkOS::InvalidRequestError,
/Invite has already been accepted/,
)
end
end
end
end

describe '.revoke_session' do
context 'with valid payload' do
it 'revokes session' do
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
http_interactions:
- request:
method: post
uri: https://api.workos.com/user_management/invitations/invitation_01H5JQDV7R7ATEYZDEG0W5PRYS/resend
body:
encoding: UTF-8
string: ''
headers:
Content-Type:
- application/json
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
Authorization:
- Bearer <API_KEY>
response:
status:
code: 400
message: Bad Request
headers:
Date:
- Mon, 17 Nov 2025 18:28:05 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Cf-Ray:
- 7fa4ef0eeafe8c12-EWR
Cf-Cache-Status:
- DYNAMIC
Etag:
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
Strict-Transport-Security:
- max-age=15552000; includeSubDomains
Vary:
- Origin, Accept-Encoding
Via:
- 1.1 spaces-router (devel)
Access-Control-Allow-Credentials:
- 'true'
Content-Security-Policy:
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
Expect-Ct:
- max-age=0
Referrer-Policy:
- no-referrer
X-Content-Type-Options:
- nosniff
X-Dns-Prefetch-Control:
- 'off'
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
X-Xss-Protection:
- '0'
Set-Cookie:
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
Secure; SameSite=None
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
HttpOnly; Secure; SameSite=None
Server:
- cloudflare
body:
encoding: ASCII-8BIT
string: '{"code":"invite_accepted","message":"Invite has already been accepted."}'
http_version:
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
recorded_with: VCR 5.0.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
http_interactions:
- request:
method: post
uri: https://api.workos.com/user_management/invitations/invitation_01H5JQDV7R7ATEYZDEG0W5PRYS/resend
body:
encoding: UTF-8
string: ''
headers:
Content-Type:
- application/json
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
Authorization:
- Bearer <API_KEY>
response:
status:
code: 400
message: Bad Request
headers:
Date:
- Mon, 17 Nov 2025 18:28:05 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Cf-Ray:
- 7fa4ef0eeafe8c12-EWR
Cf-Cache-Status:
- DYNAMIC
Etag:
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
Strict-Transport-Security:
- max-age=15552000; includeSubDomains
Vary:
- Origin, Accept-Encoding
Via:
- 1.1 spaces-router (devel)
Access-Control-Allow-Credentials:
- 'true'
Content-Security-Policy:
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
Expect-Ct:
- max-age=0
Referrer-Policy:
- no-referrer
X-Content-Type-Options:
- nosniff
X-Dns-Prefetch-Control:
- 'off'
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
X-Xss-Protection:
- '0'
Set-Cookie:
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
Secure; SameSite=None
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
HttpOnly; Secure; SameSite=None
Server:
- cloudflare
body:
encoding: ASCII-8BIT
string: '{"code":"invite_expired","message":"Invite has expired."}'
http_version:
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
recorded_with: VCR 5.0.0

Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
---
http_interactions:
- request:
method: post
uri: https://api.workos.com/user_management/invitations/invalid_id/resend
body:
encoding: UTF-8
string: ''
headers:
Content-Type:
- application/json
Accept-Encoding:
- gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept:
- "*/*"
User-Agent:
- WorkOS; ruby/3.0.2; arm64-darwin22; v2.16.0
Authorization:
- Bearer <API_KEY>
response:
status:
code: 404
message: Not Found
headers:
Date:
- Mon, 17 Nov 2025 18:28:05 GMT
Content-Type:
- application/json; charset=utf-8
Transfer-Encoding:
- chunked
Connection:
- keep-alive
Cf-Ray:
- 7fa4ef0eeafe8c12-EWR
Cf-Cache-Status:
- DYNAMIC
Etag:
- W/"56-2Auj80JGmZ1uWGCY950ud8v4KLQ"
Strict-Transport-Security:
- max-age=15552000; includeSubDomains
Vary:
- Origin, Accept-Encoding
Via:
- 1.1 spaces-router (devel)
Access-Control-Allow-Credentials:
- 'true'
Content-Security-Policy:
- 'default-src ''self'';base-uri ''self'';block-all-mixed-content;font-src ''self''
https: data:;frame-ancestors ''self'';img-src ''self'' data:;object-src ''none'';script-src
''self'';script-src-attr ''none'';style-src ''self'' https: ''unsafe-inline'';upgrade-insecure-requests'
Expect-Ct:
- max-age=0
Referrer-Policy:
- no-referrer
X-Content-Type-Options:
- nosniff
X-Dns-Prefetch-Control:
- 'off'
X-Download-Options:
- noopen
X-Frame-Options:
- SAMEORIGIN
X-Permitted-Cross-Domain-Policies:
- none
X-Request-Id:
- f5f06564-2f73-4b73-989b-b577cfbdaa9a
X-Xss-Protection:
- '0'
Set-Cookie:
- __cf_bm=v55WlV2dq1rXkfx9668LFtglSD5c9292fFLKsviMegY-1692642485-0-AWmCDzQSIwCjWvanffzmFA5KJT/nWucOWyv7i3fyyXeH+i5iM9ZusABSbNOUR6zO2mcugNYr/TRj6ltRmm8eC3M=;
path=/; expires=Mon, 21-Aug-23 18:58:05 GMT; domain=.workos.com; HttpOnly;
Secure; SameSite=None
- __cfruid=bea6b3e4c8ea6479881eb565b1ab9a0b6deabae9-1692642485; path=/; domain=.workos.com;
HttpOnly; Secure; SameSite=None
Server:
- cloudflare
body:
encoding: ASCII-8BIT
string: '{"message":"Invitation not found: ''invalid_id''.","code":"entity_not_found","entity_id":"bad_id"}'
http_version:
recorded_at: Mon, 17 Nov 2025 18:28:05 GMT
recorded_with: VCR 5.0.0

Loading
Loading