Custom Expressions with Examples Skip to main content
https://support.okta.com/help/blogdetail?id=a67f0000000bln1iai&refurl=http%3a%2f%2fsupport.okta.com%2fhelp%2fblogdetail
How satisfied are you with the Okta Help Center?
Thank you for your feedback!
How satisfied are you with the Okta Help Center?
1
2
3
4
5
Very Dissatisfied
Very satisfied
Enter content less than 200 characters.

Custom Expressions with Examples

Oct 12, 2015 | by Thomas Hill in Managing Apps with Single Sign On

Orignal Author: Lawrence York, Technical Consultant, Okta

Username Custom Expressions

Out of the box, Okta provides several default values for determining how an account should be imported and what attributes to provision to downstream applications. In most cases, these default values will accomplish majority or the customer’s requirements. However, Okta also enables customers to define their own custom attributes using custom expressions.

Use Case:

Define a username format derived from an account’s email prefix. This is accomplished using the following custom expression.

Property:  user.email = jdoe@aol.com

 

Expression: ${f:substringBefore(user.email, “@”)}

 

Result: jdoe

Expression Container

SyntaxUsageDescription
${}${function or property}

Container for evaluating functions and properties

Functions

FunctionUsageDescription
substringf:substring(property,  int, int)Returns a subset of a string
substringBeforef:substringBefore(property, “string”)Returns a subset of a string before a specific substring
substringAfterf:substringAfter(property, “string”)Returns a subset of a string after a specific substring
tolowerCasef:tolowerCase(property)Converts all of the characters of a string to lower case
toupperCasef:toUpperCase(property)Converts all of the characters of a string to upper case
replacef:replace(property, “before”, “after”)Returns a string result by replacing a "before" input string (all occurrences) with an “after” substring

Properties

PropertyDescription
user.loginUsername
user.emailEmail
user.firstNameFirst Name
user.lastNameLast Name

Escaping Backslashes

In some cases, you may need to supply a single backslash ( \ ) as a literal string. To escape a special character, precede the character with a backslash.

Example:

  ${“\\”} results in a literal string of  a single backslash ( \ )

 

Example User Data

Account attributes used for following examples and explanations.

• Firstname = Winston

• Lastname = Churchill

• Email = winston.churchill@gmail.com

• Login = winston.churchill@gmail.com

 

Custom Expression Examples

 

Value to ObtainExpressionExample Values / ResultsExplanation
Firstname${user.firstName}Winston1. Obtain the value of users's firstname attribute.
Firstname + Lastname${user.firstName}${user.lastName}WinstonChurchill1. Obtain Firstname and Lastname values and append each together
Firstname + Lastname with Separator${user.firstName}.${user.lastName}Winston.Churchill

1. Obtain Firstname value

2. Append a "." character

3. Obtain and append the Lastname value

Lower Case Firstname${f:toLowerCase(user.firstName)}winston

1. Obtain Firstname value

2. Convert result to lowercase

First Initial + Lastname${f:substring(user.firstName, 0, 1)}${user.lastName}WChurchill

1. Obtain Firstname value

2. From result, retrieve characters greater than position 0 thru position 1, including position 1

3. Obtain and append the Lastname value

First Initial + Lastname with Limit${f:substring(user.firstName, 0, 1)}${f:substring(user.lastName, 0, 6)}WChurch

1. Obtain Firstname value

2. From result, retrieve 1 character starting at the beginning of the string

3. Obtain Lastname value

4. From result, retrieve characters greater than position 0 thru position 6, including position 6

Lower Case First Initial + Lower Case Lastname with Separator${f:toLowerCase(f:substring(user.firstName, 0, 1))}.${f:toLowerCase(user.lastName)}w.churchill

1. Obtain Firstname value

2. From result, retrieve characters greater than position 0 thru position 1, including position 1

3. Convert result to lowercase

4. Append a "." character

5. Obtain the Lastname value

6. Convert to lowercase and append

Email Domain + Email Prefix with Separator${f:toUpperCase(f:substringBefore(f:substringAfter(user.email, "@"), "."))}${"\\"}${f:substringBefore(user.email, "@")}GMAIL\winston.churchill

1. Obtain Email value

2. From result, parse everything after the "@ character"

3. From result, parse everything before the "." character

4. Convert to uppercase

5. Append a backslash "\" character

6. Obtain the email value again

7. From result, parse for everything before the "@" character

Email Domain + Lowercase First Initial and Lastname with Separator${f:toUpperCase(f:substringBefore(f:substringAfter(user.email, "@"), "."))}${"\\"}${f:toLowerCase(f:substring(user.firstName, 0, 1))}${f:toLowerCase(user.lastName)}GMAIL\wchurchill

1. Obtain Email value

2. From result, parse everything after the "@ character"

3. From result, parse everything before the "." character

4. Convert to uppercase

5. Append a backslash "\" character

6. Obtain the Firstname value

7. From result, retrieve characters greater than position 0 thru position 1, including position 1

8. Convert it to lowercase

9. Obtain the Lastname value and convert it to lowercase

Static Domain + Email Prefix with SeparatorXDOMAIN${"\\"}${f:toLowerCase(f:substring(user.firstName, 0, 1))}${f:toLowerCase(user.lastName)}XDOMAIN\wchurchill

1. Add "XDOMAIN" string.

2. Append a backslash "\" character

3. Obtain the Firstname value

4. From result, retrieve characters greater than position 0 thru position 1, including position 1

5. Convert it to lowercase

6. Obtain the Lastname value

7. Convert it to lowercase

String Value Replacement${f:replace(user.email, "gmail", "gmail-dev")}winston.churchill@gmail-dev.com

1. Obtain Email value

2. Search for “gmail” string

3. Replace with “gmail-dev” string

String Value  Replacement  with Email Prefix Isolation${f:replace(f:substringBefore(user.email, "@"), ".", "_")}winston_churchill

1. Obtain Email value

2. From result, parse everything before the "@” character

3. Search for “.” character

4. Replace with “_” character

String Value Replacement - Remove Special Characters in Email Prefix
${f:substringBefore(f:replace(f:replace(f:replace(user.email, "-", ""), ".", ""), "_", ""), "@")}
winstonchurchill

1. Obtain Email value

2. Search for “-“ character and remove

3. Search for “.” character and remove

4. Search for “_” character and remove

5. From result, parse everything before the "@ character"

 

Comments