Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

30 add preferred token type config #32

Merged
merged 3 commits into from
Aug 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Tests/SDKTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,4 @@ public void TriggerChallenges()
Assert.AreEqual(webAuthnSignRequest.Replace("\n", "").Replace(" ", ""), signRequest);
}
}
}
}
15 changes: 13 additions & 2 deletions privacyIDEAADFSProvider/Adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class Adapter : IAuthenticationAdapter, PILog
private bool _enrollmentEnabled = false;
private List<string> _enrollmentApps = new List<string>();
private string _otpHint = "";
private string _preferredTokenType = "otp";
private List<string> _forwardHeaders = new List<string>();
private PrivacyIDEA _privacyIDEA;
private bool _debuglog = false;
Expand Down Expand Up @@ -136,7 +137,10 @@ public IAdapterPresentation BeginAuthentication(Claim identityClaim, HttpListene
}
}

form.Mode = "otp";
if (String.IsNullOrEmpty(form.Mode))
{
form.Mode = "otp";
}
authContext.Data.Add("userid", username);
authContext.Data.Add("domain", domain);

Expand Down Expand Up @@ -339,7 +343,7 @@ public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configD
// Read the other defined keys into a dict
List<string> configKeys = new List<string>(new string[]
{ "use_upn", "url", "disable_ssl", "tls_version", "enable_enrollment", "service_user", "service_pass", "service_realm",
"realm", "trigger_challenges", "send_empty_pass", "otp_hint", "forward_headers" });
"realm", "trigger_challenges", "send_empty_pass", "otp_hint", "forward_headers", "preferred_token_type" });

var configDict = new Dictionary<string, string>();
configKeys.ForEach(key =>
Expand Down Expand Up @@ -405,6 +409,7 @@ public void OnAuthenticationPipelineLoad(IAuthenticationMethodConfigData configD
this._privacyIDEA.SetServiceAccount(serviceUser, servicePass, GetFromDict(configDict, "service_realm"));
}
this._otpHint = GetFromDict(configDict, "otp_hint", "");
this._preferredTokenType = GetFromDict(configDict, "preferred_token_type", "otp");
this._use_upn = GetFromDict(configDict, "use_upn", "0") == "1";

this._enrollmentEnabled = GetFromDict(configDict, "enable_enrollment", "0") == "1";
Expand Down Expand Up @@ -462,6 +467,12 @@ private AdapterPresentationForm ExtractChallengeDataToForm(PIResponse response,
string webAuthnSignRequest = response.WebAuthnSignRequest();
form.WebAuthnSignRequest = webAuthnSignRequest;
}

if (response.TriggeredTokenTypes().Contains(this._preferredTokenType))
{
form.Mode = this._preferredTokenType;
}

return form;
}

Expand Down
2 changes: 1 addition & 1 deletion privacyIDEAADFSProvider/PrivacyIDEA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ private string SendRequest(string endpoint, Dictionary<string, string> parameter
foreach (var element in headers)
{
request.Headers.Add(element.Key, element.Value);
Log("Forwarding headers: " + element.Key + " = " + element.Value); // todo rm
Log("Forwarding headers: " + element.Key + " = " + element.Value);
}
}

Expand Down