-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Invite sub-org users to add email/password creds (#163)
* Invite sub-org users to add email/password creds Changes 1. Support to create a user with no login access using "/users" API 2. Invite user to attach username/password credentials using "/verifyEmail" API 3. Create password for the invited user using "/create_password" API. Test: UTs added * Bug fixes when sending user invites.
- Loading branch information
1 parent
132b0a9
commit 8968ad4
Showing
15 changed files
with
386 additions
and
137 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
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
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
36 changes: 36 additions & 0 deletions
36
src/main/kotlin/com/hypto/iam/server/extensions/SubOrganizationUtils.kt
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.hypto.iam.server.extensions | ||
|
||
import io.ktor.server.plugins.BadRequestException | ||
import java.util.Base64 | ||
|
||
/** | ||
* For sub organizations, we have to encode the email address to include the org and sub org id details in the email | ||
* so that users can have unique credentials across orgs and sub orgs. | ||
* | ||
* To support this, we are using the email local addressing scheme. This scheme allows us to add a suffix to email | ||
* address. | ||
* Ex: hello@hypto.in can be encoded as hello+<base64(orgId:subOrgId)>@hypto.in | ||
* | ||
* With this option, same email address hello@hypto.in can coonfigure two different passwords for sub orgId1 and sub | ||
* orgId2. | ||
*/ | ||
fun getEncodedEmail(organizationId: String, subOrganizationName: String?, email: String) = | ||
if (subOrganizationName != null) { | ||
encodeSubOrgUserEmail( | ||
email, | ||
organizationId, | ||
subOrganizationName | ||
) | ||
} else { | ||
} | ||
|
||
private fun encodeSubOrgUserEmail(email: String, organizationId: String, subOrganizationName: String): String { | ||
val emailParts = email.split("@").takeIf { it.size == 2 } ?: throw BadRequestException("Invalid email address") | ||
val localPart = emailParts[0] | ||
val domainPart = emailParts[1] | ||
val subAddress = Base64.getEncoder().encodeToString( | ||
"$organizationId:$subOrganizationName".toByteArray() | ||
) | ||
return "$localPart+$subAddress@$domainPart" | ||
} |
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.