├── README.md ├── coinbase.js └── example.html /README.md: -------------------------------------------------------------------------------- 1 | coinbase-javascript-sdk 2 | ======================= 3 | 4 | Use this SDK to authenticate Coinbase users using OAuth2 with Javascript. See example.html for usage. 5 | 6 | Important: https://coinbase.com/oauth/javascript_sdk_redirect must be added as a redirect URI to the OAuth2 application you are using in order for the Javascript SDK to work. 7 | -------------------------------------------------------------------------------- /coinbase.js: -------------------------------------------------------------------------------- 1 | window.Coinbase = { 2 | base_url: "https://coinbase.com", 3 | oauth: { 4 | authorize: function(params) { 5 | var url = Coinbase.base_url + '/oauth/authorize?response_type=code' 6 | var redirectUri = Coinbase.base_url + "/oauth/javascript_sdk_redirect"; 7 | url += "&redirect_uri=" + encodeURIComponent(redirectUri); 8 | url += "&client_id=" + params.clientId; 9 | if (params.scopes) { 10 | url += "&scope=" + encodeURIComponent(params.scopes); 11 | } 12 | 13 | if (params.meta) { 14 | for (var key in params.meta) { 15 | if (params.meta.hasOwnProperty(key)) { 16 | url += "&meta[" + encodeURIComponent(key) + "]=" + encodeURIComponent(params.meta[key]); 17 | } 18 | } 19 | } 20 | 21 | var width = 850; 22 | var height = 600; 23 | var left = (screen.width - width) / 2; 24 | var top = (screen.height - height) / 4; 25 | var popup = window.open(url, 'coinbase-oauth', 'width=' + width + ',height=' + height + ',left=' + left + ',top=' + top); 26 | 27 | function receiveMessage(event) { 28 | if (event.origin !== Coinbase.base_url) { 29 | return; 30 | } 31 | 32 | event.source.close(); 33 | var data = JSON.parse(event.data); 34 | params.success(data); 35 | } 36 | window.addEventListener("message", receiveMessage, false); 37 | } 38 | } 39 | }; -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 |