{"action":"created","issue":{"url":"https://api.github.com/repos/hmrc/vat-api/issues/308","repository_url":"https://api.github.com/repos/hmrc/vat-api","labels_url":"https://api.github.com/repos/hmrc/vat-api/issues/308/labels{/name}","comments_url":"https://api.github.com/repos/hmrc/vat-api/issues/308/comments","events_url":"https://api.github.com/repos/hmrc/vat-api/issues/308/events","html_url":"https://github.com/hmrc/vat-api/issues/308","id":372225283,"node_id":"MDU6SXNzdWUzNzIyMjUyODM=","number":308,"title":"HMRC VAT Tutorial 3.2 /hello/user - Delphi","user":{"login":"Yuppski","id":44003322,"node_id":"MDQ6VXNlcjQ0MDAzMzIy","avatar_url":"https://avatars0.githubusercontent.com/u/44003322?v=4","gravatar_id":"","url":"https://api.github.com/users/Yuppski","html_url":"https://github.com/Yuppski","followers_url":"https://api.github.com/users/Yuppski/followers","following_url":"https://api.github.com/users/Yuppski/following{/other_user}","gists_url":"https://api.github.com/users/Yuppski/gists{/gist_id}","starred_url":"https://api.github.com/users/Yuppski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yuppski/subscriptions","organizations_url":"https://api.github.com/users/Yuppski/orgs","repos_url":"https://api.github.com/users/Yuppski/repos","events_url":"https://api.github.com/users/Yuppski/events{/privacy}","received_events_url":"https://api.github.com/users/Yuppski/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-20T15:58:28Z","updated_at":"2018-10-22T10:03:18Z","closed_at":null,"author_association":"NONE","body":"Hi all\r\n\r\nI'm working on \"2. Exchange the OAuth 2.0 authorisation code for an access token\" of the HMRC Tutorial \"/hello/user \"\r\n\r\nI've managed to get the Authorization Code but when running the following code :-\r\n\r\nThis only occurs when building the Params at runtime.\r\n  RESTClient1.Authenticator := OAuth2Authenticator1_Hello_User;\r\n  RESTClient1.BaseURL := 'https://test-api.service.hmrc.gov.uk/oauth/token';\r\n  RESTRequest1.Method := TRESTRequestMethod.rmGET;\r\n  RESTRequest1.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkGETorPOST);\r\n  RESTRequest1.Params.AddItem('client_id', eHello_User_Client_ID.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n  RESTRequest1.Params.AddItem('client_secret', eHello_User_Client_Secret.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n  RESTRequest1.Params.AddItem('redirect_uri', eHello_User_Redirect.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n  RESTRequest1.Params.AddItem('authorization_code', eHello_User_Authorization_Code.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n  RESTRequest1.Execute;\r\n\r\n1. Enter User ID and Password\r\n2. Click Grant Access\r\n3. I get the Redirect Page and issued a Authorization Code\r\n4. Get a Exception 404 Not found \r\n•in the 400 to 499 range if it didn't succeed because of a client error by your application\r\n\r\nUsing the same OAuth2Authenticator I:-\r\n1. Right Mouse click the OAuth2Authenticator\r\n2. Select Configure\r\n3. Press Authorize\r\n4. Enter the User Id and Password\r\n5. Click Grant Access\r\n6. I get issued a Access Token and Refresh Token with no errors.\r\n\r\nI have tried the SDSTeam@hmrc.gsi.gov.uk and they suggest I use GitHub.\r\n\r\nAny ideas what I'm missing in my code?\r\n\r\nHope that makes sense.\r\ntia\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/hmrc/vat-api/issues/comments/431792363","html_url":"https://github.com/hmrc/vat-api/issues/308#issuecomment-431792363","issue_url":"https://api.github.com/repos/hmrc/vat-api/issues/308","id":431792363,"node_id":"MDEyOklzc3VlQ29tbWVudDQzMTc5MjM2Mw==","user":{"login":"Yuppski","id":44003322,"node_id":"MDQ6VXNlcjQ0MDAzMzIy","avatar_url":"https://avatars0.githubusercontent.com/u/44003322?v=4","gravatar_id":"","url":"https://api.github.com/users/Yuppski","html_url":"https://github.com/Yuppski","followers_url":"https://api.github.com/users/Yuppski/followers","following_url":"https://api.github.com/users/Yuppski/following{/other_user}","gists_url":"https://api.github.com/users/Yuppski/gists{/gist_id}","starred_url":"https://api.github.com/users/Yuppski/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Yuppski/subscriptions","organizations_url":"https://api.github.com/users/Yuppski/orgs","repos_url":"https://api.github.com/users/Yuppski/repos","events_url":"https://api.github.com/users/Yuppski/events{/privacy}","received_events_url":"https://api.github.com/users/Yuppski/received_events","type":"User","site_admin":false},"created_at":"2018-10-22T10:03:18Z","updated_at":"2018-10-22T10:03:18Z","author_association":"NONE","body":"Just to clarify this code gets called first:- \r\n  {$REGION '1. Get the the Authorisation Code'}\r\n  wv := Tfrm_OAuthWebForm.Create(self);\r\n  try\r\n    wv.OnAfterRedirect := OAuth2Authenticator1_Hello_User_Redirect;\r\n    wv.ShowModalWithURL(LURL);\r\n  finally\r\n    wv.Release;\r\n  end;\r\n  {$ENDREGION '1. Get the the Authorisation Code'}\r\n\r\nThen the sequence from the Tfrm_OAuthWebForm displays:-\r\n1. HM Revenue & Customs. Authority to interact with HMRC on your behalf. Click Continue.\r\n2. HM Revenue & Customs. Sing In. User ID and Password. Sign In.\r\n3. Click Grant Access\r\n4. Issued the Authorization Code in the code on the OAuth2Authenticator1_Hello_User_Redirect Event.\r\n5. Display my Redirect Page.\r\n6. Close the Tfrm_OAuthWebForm. \r\n\r\nFollowing code is the executed:-\r\nRESTClient1.Authenticator := OAuth2Authenticator1_Hello_User;\r\n RESTClient1.BaseURL := 'https://test-api.service.hmrc.gov.uk/oauth/token';\r\n RESTRequest1.Method := TRESTRequestMethod.rmGET;\r\n RESTRequest1.Params.AddItem('grant_type', 'authorization_code', TRESTRequestParameterKind.pkGETorPOST);\r\n RESTRequest1.Params.AddItem('client_id', eHello_User_Client_ID.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n RESTRequest1.Params.AddItem('client_secret', eHello_User_Client_Secret.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n RESTRequest1.Params.AddItem('redirect_uri', eHello_User_Redirect.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n RESTRequest1.Params.AddItem('authorization_code', eHello_User_Authorization_Code.Text, TRESTRequestParameterKind.pkGETorPOST);\r\n RESTRequest1.Execute;\r\n\r\nAn Exception is raised when calling the RESTRequest1.Execute;\r\n\r\nprocedure TfrmMain.RESTRequest1HTTPProtocolError(Sender: TCustomRESTRequest);\r\nbegin\r\n  // show error\r\n  Add_To_Memo(Sender.Response.StatusText, False{Clear_Memo});\r\n  Add_To_Memo(Sender.Response.Content, False{Clear_Memo});\r\n // Sender.Response.Content, = <!DOCTYPE html><!--[if lt IE 9]><html class=\"no-js lte-ie8\"   \r\nend;\r\n\r\nThe Sender.Response.StatusText, is \"Not Found\"\r\nThe Sender.Response.Content, is \"<!DOCTYPE html><!--[if lt IE 9]><html class=\"no-js lte-ie8\" \r\n...\r\n\"<title>HMRC Tax Platform - Page not found - 404</title>\"\r\n...\r\n\r\nHMRC say  \r\n•in the 400 to 499 range if it didn't succeed because of a client error by your application\r\n\r\nI've check and re check the application but can see what's upsetting the code when passing the Authorization Code to Get the Access & Refresh Tokens.\r\n\r\n"}}
{"actor":{"display_login":"Yuppski"}}