public ActionResult Index(CernerOAuth2ViewModels lvm) { CernerAuth myCernerAuth = TokenGettingStuff(); try { CernerFullConnectionInformationViewModel cfcivm = new CernerFullConnectionInformationViewModel { AccessToken = myCernerAuth.access_token, RefreshToken = myCernerAuth.refresh_token, PatientId = myCernerAuth.patient, ServiceUrl = myCernerHelper.cci.ServiceUrl }; FraminghamCalculatorViewModel fcvm = FraminghamCalculator(cfcivm); return(View("FraminghamCalculator", fcvm)); } catch (Exception ex) { myCernerHelper.cci.ErrorCorrelationId = myCernerAuth.CorrelationId; return(View("CernerHelper", myCernerHelper.cci)); } }
private CernerAuth TokenGettingStuff() { //Get us some information from the URL string authCode = Request.Params["code"]; string idToken = Request.Params["id_token"]; string state = Request.Params["state"]; //Have the helper get the meta data from Cerners server. myCernerHelper.GetMetaData(idToken); // Request an access token //We're going to have to do some work here for refreshing the token. OAuthHelper oauthHelper = new OAuthHelper(myCernerHelper.cci.AuthorizeUrl, myCernerHelper.cci.TokenUrl, ClientID, myCernerHelper.cci.AppSecret); // Dynamically create the redirect based on the current controllers name string redirectUri; var thisControllerName = HttpContext.Request.RequestContext.RouteData.Values["controller"].ToString(); //var thisActionName = HttpContext.Request.RequestContext.RouteData.Values["action"].ToString(); var urlBuilder = new System.UriBuilder(Request.Url.AbsoluteUri) { Path = thisControllerName, // Url.Action(thisActionName, thisControllerName), Query = null, }; //We got's to add the slash at the end to keep the OAuth server happy. redirectUri = urlBuilder.Uri.ToString() + @"/"; HttpSessionStateBase session = this.Session; Models.ViewModels.Patient viewPatient = new Models.ViewModels.Patient(); CernerAuth myCernerAuth = new CernerAuth(); //Let's go get all of that great tasting OAuth stuff with that OH SO SWEET Auth Token! myCernerAuth = oauthHelper.GetTokensFromAuthority(SMARTOnFhirConstants.TokenRequestGrantType, authCode, redirectUri, session); return(myCernerAuth); }