# Session username

**URL:** <https://discuss.hashicorp.com/t/session-username/30116>\
**Category:** Boundary\
**Created:** [September 30, 2021, 10:06am UTC](https://discuss.hashicorp.com/t/session-username/30116 "2021-09-30T10:06:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![x980707x](https://avatars.discourse-cdn.com/v4/letter/x/ecae2f/32.png) [@x980707x](https://discuss.hashicorp.com/u/x980707x)\
**Post date:** [September 30, 2021, 10:06am UTC](https://discuss.hashicorp.com/t/session-username/30116/1 "2021-09-30T10:06:07Z")

</div>

Hi,  
Can I represent Username as OIDC username in Boundary when logging in using OIDC?  
In the session menu, it is difficult to recognize users such as u\_gY7s2b0cYm, so it is not known who accessed it.

Thanks!

---

<div class="post-metadata">

**Author:** ![sikishen](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/sikishen/32/4581_2.png) [@sikishen](https://discuss.hashicorp.com/u/sikishen)\
**Post date:** [October 27, 2021, 2:32am UTC](https://discuss.hashicorp.com/t/session-username/30116/2 "2021-10-27T02:32:54Z")

</div>

Asking the same question here, as when mark OIDC as primary auth method, user will create a random uid and couldn’t claim email address or username from OIDC to add to boundary username or description.

---

<div class="post-metadata">

**Author:** ![grantorchard1](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/grantorchard1/32/17626_2.png) [@grantorchard1](https://discuss.hashicorp.com/u/grantorchard1)\
**Post date:** [November 2, 2021, 9:05pm UTC](https://discuss.hashicorp.com/t/session-username/30116/3 "2021-11-02T21:05:25Z")

</div>

Indeed you can, but you need to “pre-stage” them. A couple of questions to help with a useful example:

1. Are you managing Boundary with Terraform, or the Boundary CLI?
2. What is your Identity platform (AzureAD, Okta etc)?

Thanks!

---

<div class="post-metadata">

**Author:** ![x980707x](https://avatars.discourse-cdn.com/v4/letter/x/ecae2f/32.png) [@x980707x](https://discuss.hashicorp.com/u/x980707x)\
**Post date:** [November 3, 2021, 3:16am UTC](https://discuss.hashicorp.com/t/session-username/30116/4 "2021-11-03T03:16:29Z")

</div>

Hi @grantorchard1

1. Are you managing Boundary with Terraform, or the Boundary CLI?  
 → I’m using Terraform.
2. What is your Identity platform (AzureAD, Okta etc)?  
 → I’m using keycloak  
Thanks!

---

<div class="post-metadata">

**Author:** ![grantorchard1](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/grantorchard1/32/17626_2.png) [@grantorchard1](https://discuss.hashicorp.com/u/grantorchard1)\
**Post date:** [November 3, 2021, 4:44am UTC](https://discuss.hashicorp.com/t/session-username/30116/5 "2021-11-03T04:44:23Z")

</div>

Alright, I don’t have Keycloak here immediately to validate, but let’s go with things, and hopefully we can get through it.

Here is the code I use to setup OIDC on the Boundary side:

```auto
resource "boundary_auth_method_oidc" "this" {
  name = "global"
  scope_id = "global"
  state = "active-public"
  is_primary_for_scope = true
  callback_url = "${var.boundary_url}/v1/auth-methods/oidc:authenticate:callback"
  issuer = module.azuread_oidc.oidc_discovery_url
  client_id = module.azuread_oidc.application_client_id
  client_secret = module.azuread_oidc.azuread_application_password
  allowed_audiences = [
    module.azuread_oidc.application_client_id
  ]
  signing_algorithms = ["RS256"]
  api_url_prefix = var.boundary_url
  account_claim_maps = [
		"oid=sub"
	]
  claims_scopes = [
    "email",
    "profile"
  ]
}

```

The important thing here is the account claim map - this example uses Azure AD and I map the object\_id in as the subject for the claim.

Next up, you _probably_ want to source the user list in a similar fashion to:

```auto
variable "users" {
   type = list(string)
}

data "keycloak_user" "this" {
  for_each = toset(var.users)
  realm_id = data.keycloak_realm.master_realm.id
  username = each.value
}

```

Once you’ve got these back, you want to create an OIDC account and a user.

```auto
resource "boundary_account_oidc" "this" {
  for_each = { for v in data.keycloak_user.this: v.mail => v } #set the key to something distinct, in the case email.
  name = each.value.mail
  subject = each.value.id # I'm guessing this is the correct attribute
  auth_method_id = boundary_auth_method_oidc.this.id
}

resource "boundary_user" "this" {
  for_each = { for v in boundary_account_oidc.this : v.name => v }
  account_ids = [
    each.value.id
  ]
  name = each.value.name
  scope_id = "global"
}

```

Let me know if that works for you… it may need a little bit of tuning.

---

<div class="post-metadata">

**Author:** ![jimlambrt](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/jimlambrt/32/12946_2.png) [@jimlambrt](https://discuss.hashicorp.com/u/jimlambrt)\
**Post date:** [November 3, 2021, 10:14am UTC](https://discuss.hashicorp.com/t/session-username/30116/6 "2021-11-03T10:14:50Z")

</div>

If you populate the name and email claims in keycloak’s returned id\_token or these claims are returned from keycloak’s userinfo endpoint, then boundary will populate them in the user’s boundary OIDC account.

BTW, these claims are re-synced to the boundary OIDC account every time the user authenticates to boundary via an OIDC auth-method.

---

<div class="post-metadata">

**Author:** ![x980707x](https://avatars.discourse-cdn.com/v4/letter/x/ecae2f/32.png) [@x980707x](https://discuss.hashicorp.com/u/x980707x)\
**Post date:** [November 17, 2021, 3:22am UTC](https://discuss.hashicorp.com/t/session-username/30116/7 "2021-11-17T03:22:55Z")

</div>

Hi all!  
@grantorchard1  
Do I need to set up account\_claim\_maps and make oidc accounts and users into terraform?  
@jimlambrt  
The OIDC account shows the user’s email address.  
I want the OIDC username or email address to appear in the Users list.

Thanks!
