Skip to content

Commit

Permalink
wait authentication to populate
Browse files Browse the repository at this point in the history
  • Loading branch information
David MEJIA committed Mar 2, 2021
1 parent 464cea2 commit 270c2c4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
22 changes: 22 additions & 0 deletions keycloak/authentication_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keycloak

import (
"fmt"
"time"
)

type AuthenticationFlow struct {
Expand Down Expand Up @@ -62,6 +63,27 @@ func (keycloakClient *KeycloakClient) GetAuthenticationFlowFromAlias(realmId, al
return nil, err
}

// Retry 3 more times if not found, sometimes it took split milliseconds the Authentication to populate
if len(authenticationFlows) == 0 {
for i := 0; i < 3; i++ {
err := keycloakClient.get(fmt.Sprintf("/realms/%s/authentication/flows", realmId), &authenticationFlows, nil)

if len(authenticationFlows) > 0 {
break
}

if err != nil {
return nil, err
}

time.Sleep(time.Millisecond * 50)
}

if len(authenticationFlows) == 0 {
return nil, fmt.Errorf("no authentication flow found for alias %s", alias)
}
}

for _, authFlow := range authenticationFlows {
if authFlow.Alias == alias {
authenticationFlow = authFlow
Expand Down
4 changes: 2 additions & 2 deletions provider/data_source_keycloak_authentication_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ func dataSourceKeycloakAuthenticationFlowRead(data *schema.ResourceData, meta in
realmID := data.Get("realm_id").(string)
alias := data.Get("alias").(string)

authenticationFlow, err := keycloakClient.GetAuthenticationFlowFromAlias(realmID, alias)
authenticationFlowInfo, err := keycloakClient.GetAuthenticationFlowFromAlias(realmID, alias)
if err != nil {
return err
}

mapFromAuthenticationFlowInfoToData(data, authenticationFlow)
mapFromAuthenticationFlowInfoToData(data, authenticationFlowInfo)

return nil
}

0 comments on commit 270c2c4

Please sign in to comment.