Ejemplo n.º 1
0
        // 
        // GET: /Manage/AuthoriseEvernote
        public ActionResult AuthoriseEvernote()
        {
            EvernoteAuthorizer evernoteAuthorizer = new EvernoteAuthorizer(_evernoteOptions.URL, _evernoteOptions.SharedKey, _evernoteOptions.SharedSecret);

            RequestToken requestToken = evernoteAuthorizer.GetRequestToken("http://" + Request.Host.Value + Url.Action("EvernoteCallback", "Manage"));
      
            HttpContext.Session.SetString("RequestToken", JsonConvert.SerializeObject(requestToken));

            // Generate the Evernote URL that we will redirect the user to in order to authorise
            string callForwardUrl = evernoteAuthorizer.BuildAuthorizeUrl(requestToken);

            return Redirect(callForwardUrl);
        }
Ejemplo n.º 2
0
        // 
        // GET: /Manage/EvernoteCallback
        public async Task<ActionResult> EvernoteCallback([FromQuery] string oauth_verifier)
        {
            EvernoteCallbackViewModel evernoteCallbackViewModel = new EvernoteCallbackViewModel();

            if (String.IsNullOrEmpty(oauth_verifier))
            {
                throw new ArgumentNullException(nameof(oauth_verifier), "Problem authenticating Evernote: did not receive OAuth verifier");
            }

            EvernoteAuthorizer evernoteAuthorizer = new EvernoteAuthorizer(_evernoteOptions.URL, _evernoteOptions.SharedKey, _evernoteOptions.SharedSecret);

            RequestToken requestToken = (RequestToken)JsonConvert.DeserializeObject(HttpContext.Session.GetString("RequestToken"), typeof(RequestToken));

            EvernoteCredentials evernoteCredentials = evernoteAuthorizer.ParseAccessToken(oauth_verifier, requestToken);

            EFDbEvernoteCredentials efdbEvernoteCredentials = new EFDbEvernoteCredentials(evernoteCredentials);

            var user = await GetCurrentUserAsync();

            if (evernoteCredentials == null)
            {
                evernoteCallbackViewModel.ErrorMessage = "You did not authorise application";
                user.HasAuthorisedEvernote = false;
            }
            else
            {
                evernoteCallbackViewModel.SuccessMessage = "Evernote successfully authorised, you can now search for notes and start reading";

                _dataAccess.UpdateEvernoteCredentials(efdbEvernoteCredentials);

                user.HasAuthorisedEvernote = true;
                user.EvernoteCredentials = efdbEvernoteCredentials;
                user.EvernoteCredentialsId = efdbEvernoteCredentials.Id;
            }

            await _userManager.UpdateAsync(user);

            return View(evernoteCallbackViewModel);
        }