{"_id":"@alicloud/oauth2","_rev":"14-4d7133a1d61136e1236a96bbb27dca1b","name":"@alicloud/oauth2","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alicloud/oauth2","version":"1.0.0","dependencies":{"httpx":"^2.1.3"},"devDependencies":{"coveralls":"^3.0.2","eslint":"^5.1.0","expect.js":"^0.3.1","mocha":"^5.2.0","muk":"^0.5.3","nyc":"^12.0.2"},"main":"lib/client.js","directories":{"lib":"lib","test":"test"},"scripts":{"lint":"eslint --fix lib/* test/*","test":"mocha -R spec test/*.test.js","test-cov":"nyc --reporter=html --reporter=text mocha -R spec test/*.test.js"},"files":["lib"],"author":{"name":"Jackson Tian"},"license":"MIT","description":"AliCloud Enterprise Application OAuth2.0 client","gitHead":"bd5d6f7dcc3a06c18dbe0a76240bbcbf64c3af0d","_id":"@alicloud/oauth2@1.0.0","_npmVersion":"5.6.0","_nodeVersion":"8.9.4","_npmUser":{"name":"jacksontian","email":"shyvo1987@gmail.com"},"dist":{"integrity":"sha512-wWjUCNADISnWa9vwbTZmCvgL6TDD7Ra3Ik3whBBN8Fa87rKRUlvOydITv2Xq08zCLjxcCLRSE1DxhXAWl3HNgA==","shasum":"4674caecb8553cc982dd0de051de737160a9a336","tarball":"https://registry.npmjs.org/@alicloud/oauth2/-/oauth2-1.0.0.tgz","fileCount":3,"unpackedSize":6238,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJbUAX8CRA9TVsSAnZWagAAZ1MQAJywuUkvBnsOkdCToO0Q\nKlsy8DUtWKJyYTNrMCy7OJMHf0w7c7yVqE1vUNAIYJTzjS5ojmU2BsLV/2pr\nqDUE+23IBncMP8hrShQwCr1tn27r3OWINzOQb9Nhw8hVG2oL366jRbUAELYS\nNiN5N6lUIl2P380t9zJFauJ1/qiZ5STKpsIK/jkLjGWHMCDJZUfal+R/f7W+\nmdiCey0J9okV2iIc6NIt39EK1eydIZn87bABPK7oql9bnOIkNN5k12W0GMUY\n0CppaejneY4LoNgBYUyfNqKpavWaE8rNhYKOyC7iGEx8HCqZQapC4pH0OCUY\nHoavRXfI1GTlVuVM9sPEG6hARuhQKnjEVGs6yPjs3TUh/idSd8+QM6PRjsvU\n0d1WItr3uFyYdTROlUwhpuTetelnJmjI7CSNhe8urZE2ZajaTOq3Aqm8CvIN\nuJgTNWEp8Z/VMlRucVMxTBPTirGkpLX5qShVHnuKVK/lYIagLsTezrP/X9eJ\n5VlOx/rCZ/la0mMSb36PA8VDbMiQVxpaZCAK5jwexIZ/PcH7f6x0jiaCqkr+\nVQfQbHy143GMx6T6UoNt79KRNz5c9geC049NPDEDrnl1yaTXdj5Er36qExKS\nt6OsVDA0CwezKk1W1AVhNh3v/6u1+1CaU6hrcNHXJPifmdtj19YDwJ8SFrCq\nv5Tk\r\n=4OST\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIBiiowAoeEz97FesfyGSGnBXXdwO5Tim0qpOnww6zOUqAiEAmby8M6aXW32HBS3/EwcQERTqyN0zkvPpSUVVIZZgZ7I="}]},"maintainers":[{"name":"aleelock","email":"aleelock@126.com"},{"name":"humanhuang","email":"halfthink@gmail.com"},{"name":"jacksontian","email":"shyvo1987@gmail.com"},{"name":"ls_nodejs","email":"ls_huster@163.com"},{"name":"vangie","email":"duwan@live.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/oauth2_1.0.0_1531971068132_0.8131752748512397"},"_hasShrinkwrap":false}},"time":{"created":"2018-07-19T03:31:07.866Z","1.0.0":"2018-07-19T03:31:08.184Z","modified":"2022-04-04T12:58:05.849Z"},"maintainers":[{"email":"console-fe@alibabacloud.com","name":"console-fe"},{"email":"sdk-team@alibabacloud.com","name":"aliyunsdkteam"},{"email":"cpj1106@gmail.com","name":"pagecao"},{"email":"fengmk2@gmail.com","name":"fengmk2"},{"email":"shyvo1987@gmail.com","name":"jacksontian"}],"description":"AliCloud Enterprise Application OAuth2.0 client","author":{"name":"Jackson Tian"},"license":"MIT","readme":"# Aliyun OAuth 2.0 Node.js Client\n\nThis SDK is used support login in Web Application, more details see https://help.aliyun.com/document_detail/69962.html .\n\n## Installation\n\n```sh\n$ npm install @alicloud/oauth2\n```\n\n## Usage\n\n1. Build the client with `client id` and `client secret`\n\n```js\n// Require it\nconst AliyunOAuth2 = require('@alicloud/oauth2');\n\nconst client = new AliyunOAuth2({\n  clientId,\n  clientSecret\n});\n```\n\nThe client can be used for All user to login with OAuth 2.0.\n\n2. Get the authorize URL and let user redirect to the url\n\n```js\nconst callback = 'https://yourwebapp.com/authcallback/';\nconst scope = 'openid /acs/ccc';\nconst state = '1234567890';\nconst url = auth.getAuthorizeURL(callback, state, scope, 'offline');\n// like\n// https://signin.aliyun.com/oauth2/v1/auth?client_id=123456&redirect_uri=https%3A%2F%2Fyourwebapp.com%2Fauthcallback%2F&response_type=code&scope=openid%20%2Facs%2Fccc&access_type=offline&state=1234567890\n```\n\nAfter user login with Aliyun Web UI, it will callback to your web app with code, like:\n\n`https://yourwebapp.com/authcallback/?code=xxx`\n\n3. Use code to get access token\n\n```js\nasync function () {\n  const reuslt = await client.getAccessToken('code');\n});\n```\n\nIf ok, the result like:\n\n```json\n{\n  \"access_token\": \"eyJraWQiOiJrMTIzNCIsImVuY...\",\n  \"token_type\": \"Bearer\",\n  \"expires_in\": 3600,\n  \"refresh_token\": \"Ccx63VVeTn2dxV7ovXXfLtAqLLERAH1Bc\",\n  \"id_token\": \"eyJhbGciOiJIUzI1N...\"\n}\n```\n\nIf fails, throw an error like:\n\n```js\nvar err = new Error(`${data.error}: ${data.error_description}`);\nerr.name = 'OAuthServerError';\nerr.code = data.error;\nerr.data = {\n  httpcode: data.http_code,\n  requestid: data.request_id\n};\nthrow err;\n```\n\n4. When token expired, we can refresh it with `refresh token`\n\n```js\nasync function () {\n  const reuslt = await client.refreshAccessToken('refresh token');\n});\n```\n\nThe result is like getAccessToken return value.\n\n5. Also, If need, we can revoke the token\n\n```js\nasync function () {\n  const reuslt = await client.revokeAccessToken('access token');\n});\n```\n\n## License\nThe MIT license\n","readmeFilename":"README.md"}