/**
         * This method uses the authorization code parameter to request an access token.
         * The access token is then stored in the user session, along with other information of the signed in user.
         * Then, the method forwards the request to the Home page.
         * @author [email protected]
         * @Copyright Oracle
         */
        public ActionResult Callback(String code)
        {
            System.Diagnostics.Debug.Print("Debug ActionResult Callback");

            if (code == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                ViewBag.Title = "Callback";

                //Authentication Manager loaded with the configurations.
                IDCSClient.AuthenticationManager am = new IDCSClient.AuthenticationManager(new ConnectionOptions().GetOptions());

                //Using the Authentication Manager to exchange the Authorization Code to an Access Token.
                IDCSClient.AuthenticationResult authResult = am.authorizationCode(code);

                //Getting the Access Token object and its String value.
                String accessTokenString = authResult.getAccessToken();
                //Getting the ID Token object and its String value.
                String idTokenString = authResult.getIdToken();

                //Converting both ID and access tokens from string to corresponding objects.
                AccessToken accessToken = am.verifyAccessToken(accessTokenString);
                IdToken     idToken     = am.verifyIdToken(idTokenString);

                //Storing token objects into the HTTP Session.
                Session["accessToken"] = accessToken;
                Session["idToken"]     = idToken;

                //Setting .NET framework authentication
                String id = idToken.GetUserId();
                FormsAuthentication.SetAuthCookie(id, false);

                //Redirecting the browser to the Home page.
                return(RedirectToAction("Home", "Private"));
            }
        }
示例#2
0
 // GET: Private/MyProfile
 public ActionResult MyProfile()
 {
     if (Session["idToken"] == null)
     {
         return(RedirectToAction("Login", "Home"));
     }
     else
     {
         ViewBag.Title = "My Profile";
         //Accessing the tokens from the session.
         IdToken idToken = (IdToken)Session["idToken"];
         //Providing user information to the page.
         var user = new User()
         {
             DisplayName = idToken.GetDisplayName(),
             IdDomain    = idToken.GetIdentityDomain(),
             UserID      = idToken.GetUserId(),
             Issuer      = idToken.getIssuer(),
             Token       = idToken.getToken()
         };
         return(View(user));
     }
 }