{"_id":"56cd585aa2a95b0b00c6ec0b","category":{"_id":"56cc10b7b4cbcf0b004a5df9","project":"56cacb1bc675f50b00a4b619","__v":5,"pages":["56cd503649abf10b0036a1f0","56cd585aa2a95b0b00c6ec0b","56cd591224f28913009575c4","56cd772dd98d851d00c0c447","56d5267b1c4de4130005d804"],"version":"56cacb1cc675f50b00a4b61c","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2016-02-23T07:56:39.448Z","from_sync":false,"order":2,"slug":"sdk","title":"PHP SDK"},"project":"56cacb1bc675f50b00a4b619","version":{"_id":"56cacb1cc675f50b00a4b61c","project":"56cacb1bc675f50b00a4b619","__v":14,"createdAt":"2016-02-22T08:47:24.528Z","releaseDate":"2016-02-22T08:47:24.528Z","categories":["56cacb1dc675f50b00a4b61d","56cc10aaca43550b0028125a","56cc10b7b4cbcf0b004a5df9","56cc1bb2272aa4130002ccd2","56cc5834b4cbcf0b004a5f8b","56cda18bface161300dae13b","56d51f2873dcd20b00fb87bb","56fbe0610023171700b96105","57658310c176520e00ea9076","5772bdd48c48e00e00503638","577c1dfe87acf617003c3fcd","579525172979790e00771a15","582b4661cdfdc125000c8684","586365cedfe6cc3700a7be63"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"__v":8,"parentDoc":null,"user":"56caca84245b841300806def","updates":[],"next":{"pages":[],"description":""},"createdAt":"2016-02-24T07:14:34.158Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"settings":"","auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Authentication service forms the foundation of all the other services. This also encapsulates callbacks which propagates errors & notifications\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Parameters\"\n}\n[/block]\n\n[block:parameters]\n{\n  \"data\": {\n    \"h-0\": \"Parameter\",\n    \"h-1\": \"Type\",\n    \"0-0\": \"client_id, client_secret\",\n    \"0-1\": \"String\",\n    \"1-0\": \"environment\",\n    \"1-1\": \"ENUM\\n\\nEndpoints::ENV_SANDBOX Endpoints::ENV_PRODUCTION\",\n    \"2-0\": \"callback\",\n    \"2-1\": \"Function()\",\n    \"0-2\": \"Obtained from your CodeMojo dashboard\",\n    \"1-2\": \"Determines whether you are connecting to the test servers or production servers\",\n    \"2-2\": \"This callback carries any errors that come from the API interactions\",\n    \"h-2\": \"Description\"\n  },\n  \"cols\": 3,\n  \"rows\": 3\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"{\\n  \\\"require\\\": {\\n    \\\"codemojo/startkit\\\": \\\"0.1.*\\\"\\n  }\\n}\",\n      \"language\": \"json\",\n      \"name\": \"Composer plugin\"\n    }\n  ]\n}\n[/block]\n\n[block:api-header]\n{\n  \"type\": \"basic\",\n  \"title\": \"Usage\"\n}\n[/block]\n\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"<?php\\n\\n  use CodeMojo\\\\Client\\\\Endpoints;\\n  use CodeMojo\\\\Client\\\\Exceptions\\\\Exceptions;\\n  use CodeMojo\\\\Client\\\\Services\\\\AuthenticationService;\\n\\n  const CLIENT_ID     = 'YOUR_CLIENT_ID';\\n  const CLIENT_SECRET = 'YOUR_CLIENT_SECRET';\\n\\n  $authService = new AuthenticationService(CLIENT_ID, CLIENT_SECRET, Endpoints::ENV_SANDBOX, function($type){\\n      // Handle the exceptions appropriately\\n      switch($type){\\n          case Exceptions::AUTHENTICATION_EXCEPTION:\\n              echo 'Authentication Exception';\\n              break;\\n          case Exceptions::BALANCE_EXHAUSTED_EXCEPTION:\\n              echo 'Low balance';\\n              break;\\n          case Exceptions::FIELDS_MISSING_EXCEPTION:\\n              echo 'Fields missing';\\n              break;\\n          case Exceptions::QUOTA_EXCEPTION:\\n              echo 'Quota Exhausted Exception';\\n              break;\\n          case Exceptions::TOKEN_EXCEPTION:\\n              echo 'Invalid token Exception';\\n              break;\\n          default:\\n              echo 'Unknown exception';\\n              break;\\n      }\\n  });\",\n      \"language\": \"php\"\n    }\n  ]\n}\n[/block]\n\n[block:callout]\n{\n  \"type\": \"danger\",\n  \"title\": \"Exception Handling\",\n  \"body\": \"Please be sure to include the error callback when initializing the AuthenticationService otherwise the SDK will throw runtime exceptions\"\n}\n[/block]","excerpt":"Learn how to authenticate and generate oAuth tokens","slug":"authentication-service","type":"basic","title":"Authentication Service"}

Authentication Service

Learn how to authenticate and generate oAuth tokens

Authentication service forms the foundation of all the other services. This also encapsulates callbacks which propagates errors & notifications [block:api-header] { "type": "basic", "title": "Parameters" } [/block] [block:parameters] { "data": { "h-0": "Parameter", "h-1": "Type", "0-0": "client_id, client_secret", "0-1": "String", "1-0": "environment", "1-1": "ENUM\n\nEndpoints::ENV_SANDBOX Endpoints::ENV_PRODUCTION", "2-0": "callback", "2-1": "Function()", "0-2": "Obtained from your CodeMojo dashboard", "1-2": "Determines whether you are connecting to the test servers or production servers", "2-2": "This callback carries any errors that come from the API interactions", "h-2": "Description" }, "cols": 3, "rows": 3 } [/block] [block:code] { "codes": [ { "code": "{\n \"require\": {\n \"codemojo/startkit\": \"0.1.*\"\n }\n}", "language": "json", "name": "Composer plugin" } ] } [/block] [block:api-header] { "type": "basic", "title": "Usage" } [/block] [block:code] { "codes": [ { "code": "<?php\n\n use CodeMojo\\Client\\Endpoints;\n use CodeMojo\\Client\\Exceptions\\Exceptions;\n use CodeMojo\\Client\\Services\\AuthenticationService;\n\n const CLIENT_ID = 'YOUR_CLIENT_ID';\n const CLIENT_SECRET = 'YOUR_CLIENT_SECRET';\n\n $authService = new AuthenticationService(CLIENT_ID, CLIENT_SECRET, Endpoints::ENV_SANDBOX, function($type){\n // Handle the exceptions appropriately\n switch($type){\n case Exceptions::AUTHENTICATION_EXCEPTION:\n echo 'Authentication Exception';\n break;\n case Exceptions::BALANCE_EXHAUSTED_EXCEPTION:\n echo 'Low balance';\n break;\n case Exceptions::FIELDS_MISSING_EXCEPTION:\n echo 'Fields missing';\n break;\n case Exceptions::QUOTA_EXCEPTION:\n echo 'Quota Exhausted Exception';\n break;\n case Exceptions::TOKEN_EXCEPTION:\n echo 'Invalid token Exception';\n break;\n default:\n echo 'Unknown exception';\n break;\n }\n });", "language": "php" } ] } [/block] [block:callout] { "type": "danger", "title": "Exception Handling", "body": "Please be sure to include the error callback when initializing the AuthenticationService otherwise the SDK will throw runtime exceptions" } [/block]