This is an old revision of the document!
C# relies on Web services for ADUCID - or WSA, see Server side integration basics
Create an instance of AducidApiJsonServiceClient.
This page starts authentication request.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12; context.Response.ContentType = "application/json" ; var aducid = new AducidApiServiceClient(); //get current URI string host = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port; string query = context.Request.QueryString.ToString(); var queryParsed = HttpUtility.ParseQueryString(query); //should we display QR? var generateQr = queryParsed[ "generateQrCodePicture" ]; //create argument var arg = new requestOperationArguments(); //final URL for iOS arg.peigReturnName = host + "/authenticated" ; arg.qrCodePictureHeight = 300; arg.qrCodePictureWidth = 300; //ID to support multiple authentications in the same browser arg.id = Guid.NewGuid().ToString(); arg.generateQrCodePicture = generateQr == "true" ; try { //inititialize authentication and get response var response = aducid.startAuthenticationSession(arg); //store authId in session - security context.Session[arg.id] = response.authId; context.Response.ContentType = "application/json" ; //send repsponse to Web API context.Response.Write(aducid.toJson(response, "" )); } catch (System.ServiceModel.FaultException e) { //handle error var msgFault = e.CreateMessageFault(); var errorResult = msgFault.GetDetail<AducidClientException>().result; //get error as JSON var response = aducid.toErrorJson(errorResult, "error" ); //send JSON to Web API context.Response.Write(response); } |
OperationArgument is a simple object
1 2 3 4 5 6 7 8 |
public class OperationArgument { public String peigReturnName { get ; set ; } public int qrCodePictureHeight { get ; set ; } public int qrCodePictureWidth { get ; set ; } public String id { get ; set ; } public Boolean generateQrCodePicture { get ; set ; } } |
Just simple “Rewrite” from WSA to C# with authId check
1 2 3 4 5 |
var aducid = new AducidApiJsonServiceClient(); string host = "http://" + HttpContext.Current.Request.Url.Host + ":" + HttpContext.Current.Request.Url.Port; var response = aducid.getStatus(( string )context.Session[ "123" ]); context.Response.ContentType = "text/plain" ; context.Response.Write(response); |
On the result page we evaluate the authentication There are two basic results – authentication is OK or an error is thrown:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
var aducid = new AducidApiJsonServiceClient(); //read authId from you session string authId = ( string )context.Session[ "123" ]; var aducidResult = aducid.getResult(authId, null ); //parse json dynamic aducidResultObj = JsonConvert.DeserializeObject(aducidResult); //User primary key i.e. UDI var udi = aducidResultObj.data.userDatabaseIndex; //key to further ADUCID operetions on user object (with authId) string authKey2 = aducidResultObj.data.authKey2; //prepare response var response = aducid.endAuthenticationSession(authId, authKey2); context.Response.ContentType = "text/plain" ; //OK do something with your session //... //send response context.Response.Write(response); |
This page should contain ADUCID Integration API
Provide start, check and proxy Url.
1 2 3 |
aducid.setStartOperationUrl("open"); aducid.setResultOperationUrl("openCheck"); aducid.setProxyUrl("proxy"); |
1 2 3 4 5 6 7 8 9 |
aducid.processResult = function (result) { if (result.status == "OK") { alert("atuhenticated"); //location.reload(); } else { alert("atuhentication failure"); } } |
And create some HTML elements:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
< h1 >ADUCID Hello World example</ h1 > < div class = "row" > < div class = "col-xs-8 col-xs-offset-2" > < div class = "row" > < div class = "col-xs-8 col-xs-offset-2" > < div id = "main-button" class = "btn btn-primary btn-lg center-block" >Authenticate</ div > </ div > </ div > < div class = "row" > < img id = "qr-code" alt = "" class = "img-responsive center-block" /> </ div > < div class = "row text-center" > < div id = "qr-code-timer" class = "qr-code-timer img-responsive center-block" ></ div > < div id = "qr-code-hint" class = "qr-code-hint" ></ div > </ div > < div id = "peig-error" style = "display: none;" > < h2 >PEIG Error</ h2 > < a class = 'btn btn-lg' href = 'http://www.aducid.com/support/' data-lang = "aducid_common_installPeig" >Install PEIG</ a > < br /> < div class = 'btn btn-lg' onclick = "location.reload()" data-lang = "aducid_common_tryAgain" >Try again</ div > </ div > </ div > </ div > |