Skip to content

Commit

Permalink
Add organizationId parameter for refresh_token authentication met…
Browse files Browse the repository at this point in the history
…hod (#242)
  • Loading branch information
mthadley authored Aug 7, 2024
1 parent 18e84dc commit 07b463b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ class UserManagementApi(private val workos: WorkOS) {
fun authenticateWithRefreshToken(
clientId: String,
refreshToken: String,
organizationId: String? = null,
options: AuthenticationAdditionalOptions? = null
): RefreshAuthentication {
return workos.post(
Expand All @@ -181,6 +182,7 @@ class UserManagementApi(private val workos: WorkOS) {
clientId,
workos.apiKey,
refreshToken,
organizationId,
options
)
.build()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ import com.workos.usermanagement.types.AuthenticationWithRefreshTokenOptions
* @param clientId Identifies the application making the request to the WorkOS server.
* @param clientSecret Authenticates the application making the request to the WorkOS server.
* @param refreshToken The `refresh_token` received from a successful authentication response.
* @param organizationId The organization to issue the new `access_token` for.
* @param options The authentication options passed to the authentication request.
*/
class AuthenticationWithRefreshTokenOptionsBuilder(
private val clientId: String,
private val clientSecret: String,
private val refreshToken: String,
private val organizationId: String? = null,
private val options: AuthenticationAdditionalOptions? = null
) {
/**
Expand All @@ -26,6 +28,7 @@ class AuthenticationWithRefreshTokenOptionsBuilder(
clientSecret = this.clientSecret,
grantType = "refresh_token",
refreshToken = this.refreshToken,
organizationId = this.organizationId,
invitationToken = this.options?.invitationToken,
ipAddress = this.options?.ipAddress,
userAgent = this.options?.userAgent,
Expand All @@ -37,8 +40,8 @@ class AuthenticationWithRefreshTokenOptionsBuilder(
*/
companion object {
@JvmStatic
fun create(clientId: String, clientSecret: String, refreshToken: String, options: AuthenticationAdditionalOptions? = null): AuthenticationWithRefreshTokenOptionsBuilder {
return AuthenticationWithRefreshTokenOptionsBuilder(clientId, clientSecret, refreshToken, options)
fun create(clientId: String, clientSecret: String, refreshToken: String, organizationId: String? = null, options: AuthenticationAdditionalOptions? = null): AuthenticationWithRefreshTokenOptionsBuilder {
return AuthenticationWithRefreshTokenOptionsBuilder(clientId, clientSecret, refreshToken, organizationId, options)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ class AuthenticationWithRefreshTokenOptions @JvmOverloads constructor(
@JsonProperty("refresh_token")
val refreshToken: String,

/**
* The organization to issue the new `access_token` for.
*/
@JsonProperty("organization_id")
val organizationId: String? = null,

@JsonProperty("invitation_token")
override val invitationToken: String? = null,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ class UserManagementApiTest : TestBase() {
workos.userManagement.authenticateWithRefreshToken(
"client_id",
"refresh_token",
null,
AuthenticationAdditionalOptionsBuilder()
.ipAddress("192.0.2.1")
.userAgent("Mozilla/5.0")
Expand Down

0 comments on commit 07b463b

Please sign in to comment.