Question

Checking ASP.NET Membership Authentication from Browser Extensions using JavaScript

Hi, I have a website [Visual Studio 2012 website] that uses ASP.NET Membership with OAuth/OpenID. Now I need to create a browser extension [Using Crossrider.com APIs for Chrome, IE, Safari etc.] which will enable logged in [to my website] users to bookmark a URL from the browser extension on button click and save the URL to a database in my website using JavaScript. The website then can show the bookmarked URL for the logged in user in some DataGrid.

Now my questions are: 1. What's the best approach to do this? 2. How do you check if a user is authenticated or not from the browser extension using JavaScript? 3. How to save the bookmarked URL to the Database in my website for that logged in user?

Was it helpful?

Solution

If I understand you correctly, you want the event handler of extension button to send the URL of the active page to your website. In general, you can achieve this by capturing the URL of the active tab using appAPI.tabs.onTabSelectionChanged and then using appAPI.request.get (or post) to send the data to your website database.

Regarding the user credentials, assuming you are authenticating the user in the extension, you can save the credentials to the local database using appAPI.db.set (get to retrieve the data) and send it as part of the request to save the URL. The following code shows the principle idea:

In the background.js file, implement the button handler and saving the URL to your site:

appAPI.ready(function() {
  var activeUrl = null;

  // Keep track of the active tab's URL
  appAPI.tabs/onTabSelectionChanged(function(tabInfo) {
    activeUrl = tabInfo.tabUrl;
  });

  // Configure the extension's button
  appAPI.browserAction.setResourceIcon('icon.png');
  appAPI.browserAction.click(function() {
    // Send bookmark to your website
    appAPI.request.post({
      url: <YOUR_WEBSITE_URL>,
      postData: {
        bookmark: activeUrl,
        token: appAPI.db.get('userToken'); // User Credentials
      }
    });
  });
});

In the extension.js file, save user credentials to the extension's database:

appAPI.ready(function($) {
  // Your authentication code
  ...
  userToken = ...;
  // Save the credentials
  appAPI.db.set('userToken', userToken)
});

If you require further assistance and feel that stackoverflow is not the appropriate forum to discuss the specifics, please email our support team (support@crossrider.com).

Disclaimer: I am a Crossrider employee

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top