{"id":13432709,"url":"https://github.com/oauth-io/oauth-js","last_synced_at":"2025-10-22T11:43:08.724Z","repository":{"id":8958964,"uuid":"10697956","full_name":"oauth-io/oauth-js","owner":"oauth-io","description":"OAuth that just works ! This is the JavaScript SDK for OAuth.io","archived":false,"fork":false,"pushed_at":"2017-12-31T04:24:28.000Z","size":2995,"stargazers_count":794,"open_issues_count":30,"forks_count":196,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-03-08T09:36:00.348Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://oauth.io","language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oauth-io.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-06-14T21:17:22.000Z","updated_at":"2025-03-04T11:15:48.000Z","dependencies_parsed_at":"2022-09-01T18:42:47.330Z","dependency_job_id":null,"html_url":"https://github.com/oauth-io/oauth-js","commit_stats":null,"previous_names":[],"tags_count":28,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauth-io%2Foauth-js","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauth-io%2Foauth-js/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauth-io%2Foauth-js/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oauth-io%2Foauth-js/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oauth-io","download_url":"https://codeload.github.com/oauth-io/oauth-js/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244016808,"owners_count":20384210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-31T02:01:15.562Z","updated_at":"2025-10-22T11:43:08.641Z","avatar_url":"https://github.com/oauth-io.png","language":"CoffeeScript","funding_links":[],"categories":["JavaScript","CoffeeScript"],"sub_categories":[],"readme":"OAuth.io JavaScript SDK\n=======================\n\nThis is the JavaScript SDK for [OAuth.io](https://oauth.io). OAuth.io allows you to integrate **100+ providers** really easily in your web app, without worrying about each provider's OAuth specific implementation.\n\nInstallation\n============\n\nGetting the SDK\n---------------\n\nTo get the SDK, you can :\n\n- download the zip file from this repository\n- get it via Bower or npm (for browserify)\n\n**Zip file**\n\nJust copy the dist/oauth.js or dist/oauth.min.js to your project.\n\n**Bower**\n\n```sh\n$ bower install oauthio-web\n```\n\n**npm for browserify**\n\n```sh\n$ npm install oauthio-web\n```\n\n\nIntegrating in your project\n---------------------------\n\nIn the `\u003chead\u003e` of your HTML, include OAuth.js\n\n`\u003cscript src=\"/path/to/oauth.js\"\u003e\u003c/script\u003e`\n\nIn your Javascript, add this line to initialize OAuth.js\n\n`OAuth.initialize('your_app_public_key');`\n\nUsage\n=====\n\nTo connect your user using facebook, 2 methods:\n\nPopup mode\n----------\n\n ```javascript\n//Using popup (option 1)\nOAuth.popup('facebook')\n.done(function(result) {\n  //use result.access_token in your API request \n  //or use result.get|post|put|del|patch|me methods (see below)\n})\n.fail(function (err) {\n  //handle error with err\n});\n ```\n\nRedirection mode\n----------------\n\n ```javascript\n//Using redirection (option 2)\nOAuth.redirect('facebook', \"callback/url\");\n ```\n\nIn callback url :\n\n ```javascript\nOAuth.callback('facebook')\n.done(function(result) {\n    //use result.access_token in your API request\n    //or use result.get|post|put|del|patch|me methods (see below)\n})\n.fail(function (err) {\n    //handle error with err\n});\n ```\n\nMaking requests\n---------------\n\nYou can make requests to the provider's API manually with the access token you got from the `popup` or `callback` methods, or use the request methods stored in the `result` object.\n\n**GET Request**\n\nTo make a GET request, you have to call the `result.get` method like this :\n\n```javascript\n//Let's say the /me endpoint on the provider API returns a JSON object\n//with the field \"name\" containing the name \"John Doe\"\nOAuth.popup(provider)\n.done(function(result) {\n    result.get('/me')\n    .done(function (response) {\n        //this will display \"John Doe\" in the console\n        console.log(response.name);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n**POST Request**\n\nTo make a POST request, you have to call the `result.post` method like this :\n\n```javascript\n//Let's say the /message endpoint on the provider waits for\n//a POST request containing the fields \"user_id\" and \"content\"\n//and returns the field \"id\" containing the id of the sent message \nOAuth.popup(provider)\n.done(function(result) {\n    result.post('/message', {\n        data: {\n            user_id: 93,\n            content: 'Hello Mr. 93 !'\n        }\n    })\n    .done(function (response) {\n        //this will display the id of the message in the console\n        console.log(response.id);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n**PUT Request**\n\nTo make a PUT request, you have to call the `result.post` method like this :\n\n```javascript\n//Let's say the /profile endpoint on the provider waits for\n//a PUT request to update the authenticated user's profile \n//containing the field \"name\" and returns the field \"name\" \n//containing the new name\nOAuth.popup(provider)\n.done(function(result) {\n    result.put('/message', {\n        data: {\n            name: \"John Williams Doe III\"\n        }\n    })\n    .done(function (response) {\n        //this will display the new name in the console\n        console.log(response.name);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n**PATCH Request**\n\nTo make a PATCH request, you have to call the `result.patch` method like this :\n\n```javascript\n//Let's say the /profile endpoint on the provider waits for\n//a PATCH request to update the authenticated user's profile \n//containing the field \"name\" and returns the field \"name\" \n//containing the new name\nOAuth.popup(provider)\n.done(function(result) {\n    result.patch('/message', {\n        data: {\n            name: \"John Williams Doe III\"\n        }\n    })\n    .done(function (response) {\n        //this will display the new name in the console\n        console.log(response.name);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n**DELETE Request**\n\nTo make a DELETE request, you have to call the `result.del` method like this :\n\n```javascript\n//Let's say the /picture?id=picture_id endpoint on the provider waits for\n//a DELETE request to delete a picture with the id \"84\"\n//and returns true or false depending on the user's rights on the picture\nOAuth.popup(provider)\n.done(function(result) {\n    result.del('/picture?id=84')\n    .done(function (response) {\n        //this will display true if the user was authorized to delete\n        //the picture\n        console.log(response);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n**Me() Request**\n\nThe `me()` request is an OAuth.io feature that allows you, when the provider is supported, to retrieve a unified object describing the authenticated user. That can be very useful when you need to login a user via several providers, but don't want to handle a different response each time.\n\nTo use the `me()` feature, do like the following (the example works for Facebook, Github, Twitter and many other providers in this case) :\n\n```javascript\n//provider can be 'facebook', 'twitter', 'github', or any supported\n//provider that contain the fields 'firstname' and 'lastname' \n//or an equivalent (e.g. \"FirstName\" or \"first-name\")\nvar provider = 'facebook';\n\nOAuth.popup(provider)\n.done(function(result) {\n    result.me()\n    .done(function (response) {\n        console.log('Firstname: ', response.firstname);\n        console.log('Lastname: ', response.lastname);\n    })\n    .fail(function (err) {\n        //handle error with err\n    });\n})\n.fail(function (err) {\n    //handle error with err\n});\n```\n\n*Filtering the results*\n\nYou can filter the results of the `me()` method by passing an array of fields you need :\n\n```javascript\n//...\nresult.me(['firstname', 'lastname', 'email'/*, ...*/])\n//...\n```\n\n\nContributing\n============\n\nYou are welcome to fork and make pull requests. We will be happy to review them and include them in the code if they bring nice improvements :)\n\nTesting the SDK\n===============\n\nTo test the SDK, you first need to install the npm modules `jasmine-node` and `istanbul` (to get the tests coverage) :\n\n```sh\n$ sudo npm install -g jasmine-node@2.0.0 istanbul\n```\n\nThen you can run the testsuite from the SDK root directory :\n\n```sh\n$ jasmine-node --verbose tests/unit/spec\n```\n\nOnce you've installed `istanbul`, you can run the following command to get coverage information :\n\n```sh\n$ npm test\n```\n\nThe coverage report is generated in the `coverage` folder. You can have a nice HTML render of the report in `coverage/lcof-report/index.html`\n\nLicense\n=======\n\nThis SDK is published under the Apache2 License.\n\n\n\nMore information in [oauth.io documentation](http://oauth.io/#/docs)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foauth-io%2Foauth-js","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foauth-io%2Foauth-js","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foauth-io%2Foauth-js/lists"}