/// <summary> /// Write oxd settings into json file /// </summary> /// <param name="oxd">oxd models</param> /// <param name="setupClientResponse">oxd setup client response from oxd server</param> public void SetConfigValues(OxdModel oxd, SetupClientResponse setupClientResponse) { string configObjString = System.IO.File.ReadAllText(Server.MapPath(@ConfigurationManager.AppSettings["oxd_config"])); OxdSetting oxdsettings = JsonConvert.DeserializeObject <OxdSetting>(configObjString); oxdsettings.AuthUrl = oxd.RedirectUrl; oxdsettings.OpHost = oxd.OpHost; oxdsettings.PostLogoutRedirectUrl = oxd.PostLogoutRedirectUrl; oxdsettings.ClientName = oxd.ClientName; oxdsettings.ConnectionType = oxd.ConnectionType; oxdsettings.OxdId = setupClientResponse.Data.OxdId; oxdsettings.ClientId = setupClientResponse.Data.clientId; oxdsettings.ClientSecret = setupClientResponse.Data.clientSecret; if (oxd.ConnectionType == "local") { oxdsettings.OxdPort = oxd.OxdPort; } else if (oxd.ConnectionType == "web") { oxdsettings.HttpRestUrl = oxd.HttpRestUrl; } oxdsettings.DynamicRegistration = (isDynamicRegistration(oxd.OpHost) == true) ? true : false; string updatejsonstring = Newtonsoft.Json.JsonConvert.SerializeObject(oxdsettings, Newtonsoft.Json.Formatting.None); System.IO.File.WriteAllText(Server.MapPath(@ConfigurationManager.AppSettings["oxd_config"]), updatejsonstring); }
public ActionResult Update(OxdModel oxd) { Loadoxdsettings(); string updateStatus = "ok"; if (dynamic_registration) { var updateSiteInputParams = new UpdateSiteParams(); var updateSiteClient = new UpdateSiteRegistrationClient(); updateSiteInputParams.AuthorizationRedirectUri = oxd.RedirectUrl; updateSiteInputParams.PostLogoutRedirectUri = oxd.PostLogoutRedirectUrl; updateSiteInputParams.ClientName = oxd.ClientName; updateSiteInputParams.OxdId = oxd.OxdId; updateSiteInputParams.Contacts = new List <string> { oxd.OxdEmail }; updateSiteInputParams.PostLogoutRedirectUri = oxd.PostLogoutRedirectUrl; updateSiteInputParams.GrantTypes = grant_types; //updateSiteInputParams.Scope = scope; var updateSiteResponse = new UpdateSiteResponse(); //Update Client using OXD Local if (oxd.ConnectionType == "local") { //Get ProtectionAccessToken updateSiteInputParams.ProtectionAccessToken = GetProtectionAccessToken(oxdHost, oxd.OxdPort); // Update Site response updateSiteResponse = updateSiteClient.UpdateSiteRegistration(oxdHost, oxd.OxdPort, updateSiteInputParams); } //Update Client using OXD Web if (oxd.ConnectionType == "web") { updateSiteInputParams.ProtectionAccessToken = GetProtectionAccessToken(oxd.HttpRestUrl); updateSiteResponse = updateSiteClient.UpdateSiteRegistration(oxd.HttpRestUrl, updateSiteInputParams); } updateStatus = updateSiteResponse.Status; } Updateoxdsettingfile(oxd); //Process Response return(Json(new { status = updateStatus })); }
/// <summary> /// updates oxd settings value in the json file /// </summary> /// <param name="oxd"></param> private void Updateoxdsettingfile(OxdModel oxd) { string configObjString = System.IO.File.ReadAllText(Server.MapPath(@ConfigurationManager.AppSettings["oxd_config"])); OxdSetting oxdsettings = JsonConvert.DeserializeObject <OxdSetting>(configObjString); oxdsettings.AuthUrl = oxd.RedirectUrl; oxdsettings.PostLogoutRedirectUrl = oxd.PostLogoutRedirectUrl; oxdsettings.OpHost = oxd.OpHost; oxdsettings.ConnectionType = oxd.ConnectionType; oxdsettings.ClientId = oxd.ClientId; oxdsettings.ClientSecret = oxd.ClientSecret; oxdsettings.ClientName = oxd.ClientName; oxdsettings.OxdPort = oxd.OxdPort; oxdsettings.HttpRestUrl = oxd.HttpRestUrl; string updatejsonstring = JsonConvert.SerializeObject(oxdsettings, Newtonsoft.Json.Formatting.None); System.IO.File.WriteAllText(Server.MapPath(@ConfigurationManager.AppSettings["oxd_config"]), updatejsonstring); }
public ActionResult SetupClient(OxdModel oxd) { Loadoxdsettings(); var setupClientInputParams = new SetupClientParams(); var registerSiteClient = new SetupClientClient(); //prepare input params for Setup client setupClientInputParams.AuthorizationRedirectUri = oxd.RedirectUrl; setupClientInputParams.OpHost = oxd.OpHost; setupClientInputParams.PostLogoutRedirectUri = oxd.PostLogoutRedirectUrl; setupClientInputParams.ClientName = oxd.ClientName; setupClientInputParams.Scope = scope; setupClientInputParams.GrantTypes = grant_types; // setupClientInputParams.ClientId = oxd.ClientId; // setupClientInputParams.ClientSecret = oxd.ClientSecret; var setupClientResponse = new SetupClientResponse(); if (string.IsNullOrEmpty(oxd.OxdId)) { //Setup Client using OXD Local if (oxd.ConnectionType == "local") { setupClientResponse = registerSiteClient.SetupClient(oxdHost, oxd.OxdPort, setupClientInputParams); } //Setup Client using OXD Web if (oxd.ConnectionType == "web") { setupClientResponse = registerSiteClient.SetupClient(oxd.HttpRestUrl, setupClientInputParams); } SetConfigValues(oxd, setupClientResponse); return(Json(new { oxdId = setupClientResponse.Data.OxdId, clientId = setupClientResponse.Data.clientId, clientSecret = setupClientResponse.Data.clientSecret })); } else { return(Json(new { oxdId = oxd.OxdId, clientId = clientid, clientSecret = clientsecret })); } }
public ActionResult Index(OxdModel oxd) { Loadoxdsettings(); var getAuthUrlInputParams = new GetAuthorizationUrlParams(); var getAuthUrlClient = new GetAuthorizationUrlClient(); //prepare input params for Getting Auth URL from a site getAuthUrlInputParams.OxdId = oxd_id; getAuthUrlInputParams.custom_parameters.Add("param1", "value1"); getAuthUrlInputParams.custom_parameters.Add("param2", "value2"); var getAuthUrlResponse = new GetAuthorizationUrlResponse(); //Get Authorization url using OXD Local if (OXDType == "local") { //Get ProtectionAccessToken if (dynamic_registration) { getAuthUrlInputParams.ProtectionAccessToken = GetProtectionAccessToken(oxdHost, oxdPort); } //Get Auth URL getAuthUrlResponse = getAuthUrlClient.GetAuthorizationURL(oxdHost, oxdPort, getAuthUrlInputParams); } //Get Authorization url using OXD Web if (OXDType == "web") { if (dynamic_registration) { getAuthUrlInputParams.ProtectionAccessToken = GetProtectionAccessToken(httpresturl); } getAuthUrlResponse = getAuthUrlClient.GetAuthorizationURL(httpresturl, getAuthUrlInputParams); } //Process Response return(Json(new { authUrl = getAuthUrlResponse.Data.AuthorizationUrl })); }
public ActionResult GetUserInfo() { string code = Request.Params["code"]; string state = Request.Params["state"]; if (code == null && state == null) { return(RedirectToAction("Index")); } OxdModel oxd = new OxdModel(); #region GetProtectionAccessToken string protectionAccessToken = ""; if (dynamic_registration) { //For OXD Server if (OXDType == "local") { //Get ProtectionAccessToken protectionAccessToken = GetProtectionAccessToken(oxdHost, oxdPort); } //For OXD Web if (OXDType == "web") { protectionAccessToken = GetProtectionAccessToken(httpresturl); } } #endregion #region Get Tokens by Code var getTokenByCodeInputParams = new GetTokensByCodeParams(); var getTokenByCodeClient = new GetTokensByCodeClient(); //prepare input params for Getting Tokens from a site getTokenByCodeInputParams.OxdId = oxd_id; getTokenByCodeInputParams.Code = code; getTokenByCodeInputParams.State = state; getTokenByCodeInputParams.ProtectionAccessToken = protectionAccessToken; var getTokensByCodeResponse = new GetTokensByCodeResponse(); //For OXD Server if (OXDType == "local") { getTokensByCodeResponse = getTokenByCodeClient.GetTokensByCode(oxdHost, oxdPort, getTokenByCodeInputParams); } //For OXD Web if (OXDType == "web") { getTokensByCodeResponse = getTokenByCodeClient.GetTokensByCode(httpresturl, getTokenByCodeInputParams); } var accessToken = getTokensByCodeResponse.Data.AccessToken; var refreshToken = getTokensByCodeResponse.Data.RefreshToken; #endregion #region Get Access Token By Refresh Token if (dynamic_registration) { var getAccessTokenByRefreshTokenInputParams = new GetAccessTokenByRefreshTokenParams(); var getAccessTokenByRefreshTokenClient = new GetAccessTokenByRefreshTokenClient(); //prepare input params for Getting Tokens from a site getAccessTokenByRefreshTokenInputParams.OxdId = oxd_id; getAccessTokenByRefreshTokenInputParams.RefreshToken = refreshToken; getAccessTokenByRefreshTokenInputParams.ProtectionAccessToken = protectionAccessToken; var getAccessTokenByRefreshTokenResponse = new GetAccessTokenByRefreshTokenResponse(); //For OXD Server if (OXDType == "local") { getAccessTokenByRefreshTokenResponse = getAccessTokenByRefreshTokenClient.GetAccessTokenByRefreshToken(oxdHost, oxdPort, getAccessTokenByRefreshTokenInputParams); } //For OXD Web if (OXDType == "web") { getAccessTokenByRefreshTokenResponse = getAccessTokenByRefreshTokenClient.GetAccessTokenByRefreshToken(httpresturl, getAccessTokenByRefreshTokenInputParams); } accessToken = getAccessTokenByRefreshTokenResponse.Data.AccessToken; refreshToken = getAccessTokenByRefreshTokenResponse.Data.RefreshToken; } #endregion #region Get User Info var getUserInfoInputParams = new GetUserInfoParams(); var getUserInfoClient = new GetUserInfoClient(); //prepare input params for Getting User Info from a site getUserInfoInputParams.OxdId = oxd_id; getUserInfoInputParams.AccessToken = accessToken; getUserInfoInputParams.ProtectionAccessToken = protectionAccessToken; var getUserInfoResponse = new GetUserInfoResponse(); //For OXD Server if (OXDType == "local") { getUserInfoResponse = getUserInfoClient.GetUserInfo(oxdHost, oxdPort, getUserInfoInputParams); } //For OXD Web if (OXDType == "web") { getUserInfoResponse = getUserInfoClient.GetUserInfo(httpresturl, getUserInfoInputParams); } //Process response Session["userName"] = getUserInfoResponse.Data.UserClaims["name"].FirstOrDefault(); Session["userEmail"] = getUserInfoResponse.Data.UserClaims["email"] == null ? string.Empty : getUserInfoResponse.Data.UserClaims["email"].FirstOrDefault(); #endregion return(RedirectToAction("UserInfo")); }