{"action":"created","comment":{"url":"https://api.github.com/repos/kennydo/artesia/pulls/comments/191083473","pull_request_review_id":123590835,"id":191083473,"diff_hunk":"@@ -0,0 +1,121 @@\n+package oauth\n+\n+import (\n+\t\"github.com/RangelReale/osin\"\n+\t\"github.com/jmoiron/sqlx\"\n+)\n+\n+// Service implements the Oauth service, returning Oauth data from the DB\n+type Service struct {\n+\tdb *sqlx.DB\n+}\n+\n+// AuthorizeID is the ID of an authorization object\n+type AuthorizeID string\n+\n+// GetClientByID returns an osin.Client by its ID\n+func (s *Service) GetClientByID(id int) (osin.Client, error) {\n+\tdbClient := Client{}\n+\terr := s.db.Get(&dbClient, \"SELECT * FROM clients WHERE id = $1\", id)\n+\tif err != nil {\n+\t\treturn &osin.DefaultClient{}, err\n+\t}\n+\treturn &osin.DefaultClient{\n+\t\tId:          dbClient.ExternalID,\n+\t\tSecret:      dbClient.Secret,\n+\t\tRedirectUri: dbClient.RedirectURI,\n+\t\tUserData:    dbClient.UserData,\n+\t}, nil\n+}\n+\n+// GetAuthorizationClientByID returns osin.AuthorizationData for a client\n+// TODO: make canned erors\n+func (s *Service) GetAuthorizationClientByID(id int) (osin.AuthorizeData, error) {\n+\tdbAuthorization := Authorization{}\n+\terr := s.db.Get(&dbAuthorization, \"SELECT * FROM authorizations WHERE client_id = $1\", id)\n+\tif err != nil {\n+\t\treturn osin.AuthorizeData{}, err\n+\t}\n+\n+\tclient, err := s.GetClientByID(dbAuthorization.ClientID)\n+\tif err != nil {\n+\t\treturn osin.AuthorizeData{}, err\n+\t}\n+\n+\treturn osin.AuthorizeData{\n+\t\tClient:      client,\n+\t\tCode:        dbAuthorization.Code,\n+\t\tExpiresIn:   dbAuthorization.Expiration,\n+\t\tScope:       dbAuthorization.Scope,\n+\t\tRedirectUri: dbAuthorization.RedirectURI,\n+\t\tUserData:    dbAuthorization.UserData,\n+\t}, nil\n+}\n+\n+// CreateClient creates a client DB object\n+func (s *Service) CreateClient(client osin.Client) error {\n+\t_, err := s.db.Exec(\n+\t\t`INSERT INTO clients (\n+                        external_id,\n+                        secret,\n+                        redirect_uri,\n+                        user_data) VALUES ($1, $2, $3, $4)`,\n+\t\tclient.GetId(),\n+\t\tclient.GetSecret(),\n+\t\tclient.GetRedirectUri(),\n+\t\tclient.GetUserData(),\n+\t)\n+\treturn err\n+}\n+\n+// CreateAuthorizationData creates a DB authorization object\n+func (s *Service) CreateAuthorizationData(data osin.AuthorizeData) error {","path":"lib/services/oauth/service.go","position":72,"original_position":72,"commit_id":"6859089319c6a9758fd93cf5f38a83d214a9ea97","original_commit_id":"6859089319c6a9758fd93cf5f38a83d214a9ea97","user":{"login":"Koshroy","id":1709579,"avatar_url":"https://avatars3.githubusercontent.com/u/1709579?v=4","gravatar_id":"","url":"https://api.github.com/users/Koshroy","html_url":"https://github.com/Koshroy","followers_url":"https://api.github.com/users/Koshroy/followers","following_url":"https://api.github.com/users/Koshroy/following{/other_user}","gists_url":"https://api.github.com/users/Koshroy/gists{/gist_id}","starred_url":"https://api.github.com/users/Koshroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koshroy/subscriptions","organizations_url":"https://api.github.com/users/Koshroy/orgs","repos_url":"https://api.github.com/users/Koshroy/repos","events_url":"https://api.github.com/users/Koshroy/events{/privacy}","received_events_url":"https://api.github.com/users/Koshroy/received_events","type":"User","site_admin":false},"body":"I decided to not have it return the newly created object, because these methods just de/serialize `osin` objects, but if you feel that we should return the object, then I can do that.","created_at":"2018-05-27T17:44:13Z","updated_at":"2018-05-27T17:44:13Z","html_url":"https://github.com/kennydo/artesia/pull/8#discussion_r191083473","pull_request_url":"https://api.github.com/repos/kennydo/artesia/pulls/8","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/comments/191083473"},"html":{"href":"https://github.com/kennydo/artesia/pull/8#discussion_r191083473"},"pull_request":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/8"}},"in_reply_to_id":191065893},"pull_request":{"url":"https://api.github.com/repos/kennydo/artesia/pulls/8","id":190771860,"html_url":"https://github.com/kennydo/artesia/pull/8","diff_url":"https://github.com/kennydo/artesia/pull/8.diff","patch_url":"https://github.com/kennydo/artesia/pull/8.patch","issue_url":"https://api.github.com/repos/kennydo/artesia/issues/8","number":8,"state":"open","locked":false,"title":"CRUD for OAuth","user":{"login":"Koshroy","id":1709579,"avatar_url":"https://avatars3.githubusercontent.com/u/1709579?v=4","gravatar_id":"","url":"https://api.github.com/users/Koshroy","html_url":"https://github.com/Koshroy","followers_url":"https://api.github.com/users/Koshroy/followers","following_url":"https://api.github.com/users/Koshroy/following{/other_user}","gists_url":"https://api.github.com/users/Koshroy/gists{/gist_id}","starred_url":"https://api.github.com/users/Koshroy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Koshroy/subscriptions","organizations_url":"https://api.github.com/users/Koshroy/orgs","repos_url":"https://api.github.com/users/Koshroy/repos","events_url":"https://api.github.com/users/Koshroy/events{/privacy}","received_events_url":"https://api.github.com/users/Koshroy/received_events","type":"User","site_admin":false},"body":"","created_at":"2018-05-27T05:45:49Z","updated_at":"2018-05-27T17:44:13Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2ea06a9a40f2f89076b664e14d793b068c321547","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/kennydo/artesia/pulls/8/commits","review_comments_url":"https://api.github.com/repos/kennydo/artesia/pulls/8/comments","review_comment_url":"https://api.github.com/repos/kennydo/artesia/pulls/comments{/number}","comments_url":"https://api.github.com/repos/kennydo/artesia/issues/8/comments","statuses_url":"https://api.github.com/repos/kennydo/artesia/statuses/6859089319c6a9758fd93cf5f38a83d214a9ea97","head":{"label":"kennydo:oauth-crud","ref":"oauth-crud","sha":"6859089319c6a9758fd93cf5f38a83d214a9ea97","user":{"login":"kennydo","id":897349,"avatar_url":"https://avatars3.githubusercontent.com/u/897349?v=4","gravatar_id":"","url":"https://api.github.com/users/kennydo","html_url":"https://github.com/kennydo","followers_url":"https://api.github.com/users/kennydo/followers","following_url":"https://api.github.com/users/kennydo/following{/other_user}","gists_url":"https://api.github.com/users/kennydo/gists{/gist_id}","starred_url":"https://api.github.com/users/kennydo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennydo/subscriptions","organizations_url":"https://api.github.com/users/kennydo/orgs","repos_url":"https://api.github.com/users/kennydo/repos","events_url":"https://api.github.com/users/kennydo/events{/privacy}","received_events_url":"https://api.github.com/users/kennydo/received_events","type":"User","site_admin":false},"repo":{"id":133190341,"name":"artesia","full_name":"kennydo/artesia","owner":{"login":"kennydo","id":897349,"avatar_url":"https://avatars3.githubusercontent.com/u/897349?v=4","gravatar_id":"","url":"https://api.github.com/users/kennydo","html_url":"https://github.com/kennydo","followers_url":"https://api.github.com/users/kennydo/followers","following_url":"https://api.github.com/users/kennydo/following{/other_user}","gists_url":"https://api.github.com/users/kennydo/gists{/gist_id}","starred_url":"https://api.github.com/users/kennydo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennydo/subscriptions","organizations_url":"https://api.github.com/users/kennydo/orgs","repos_url":"https://api.github.com/users/kennydo/repos","events_url":"https://api.github.com/users/kennydo/events{/privacy}","received_events_url":"https://api.github.com/users/kennydo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kennydo/artesia","description":null,"fork":false,"url":"https://api.github.com/repos/kennydo/artesia","forks_url":"https://api.github.com/repos/kennydo/artesia/forks","keys_url":"https://api.github.com/repos/kennydo/artesia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kennydo/artesia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kennydo/artesia/teams","hooks_url":"https://api.github.com/repos/kennydo/artesia/hooks","issue_events_url":"https://api.github.com/repos/kennydo/artesia/issues/events{/number}","events_url":"https://api.github.com/repos/kennydo/artesia/events","assignees_url":"https://api.github.com/repos/kennydo/artesia/assignees{/user}","branches_url":"https://api.github.com/repos/kennydo/artesia/branches{/branch}","tags_url":"https://api.github.com/repos/kennydo/artesia/tags","blobs_url":"https://api.github.com/repos/kennydo/artesia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kennydo/artesia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kennydo/artesia/git/refs{/sha}","trees_url":"https://api.github.com/repos/kennydo/artesia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kennydo/artesia/statuses/{sha}","languages_url":"https://api.github.com/repos/kennydo/artesia/languages","stargazers_url":"https://api.github.com/repos/kennydo/artesia/stargazers","contributors_url":"https://api.github.com/repos/kennydo/artesia/contributors","subscribers_url":"https://api.github.com/repos/kennydo/artesia/subscribers","subscription_url":"https://api.github.com/repos/kennydo/artesia/subscription","commits_url":"https://api.github.com/repos/kennydo/artesia/commits{/sha}","git_commits_url":"https://api.github.com/repos/kennydo/artesia/git/commits{/sha}","comments_url":"https://api.github.com/repos/kennydo/artesia/comments{/number}","issue_comment_url":"https://api.github.com/repos/kennydo/artesia/issues/comments{/number}","contents_url":"https://api.github.com/repos/kennydo/artesia/contents/{+path}","compare_url":"https://api.github.com/repos/kennydo/artesia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kennydo/artesia/merges","archive_url":"https://api.github.com/repos/kennydo/artesia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kennydo/artesia/downloads","issues_url":"https://api.github.com/repos/kennydo/artesia/issues{/number}","pulls_url":"https://api.github.com/repos/kennydo/artesia/pulls{/number}","milestones_url":"https://api.github.com/repos/kennydo/artesia/milestones{/number}","notifications_url":"https://api.github.com/repos/kennydo/artesia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kennydo/artesia/labels{/name}","releases_url":"https://api.github.com/repos/kennydo/artesia/releases{/id}","deployments_url":"https://api.github.com/repos/kennydo/artesia/deployments","created_at":"2018-05-12T23:20:48Z","updated_at":"2018-05-26T07:29:18Z","pushed_at":"2018-05-27T05:45:49Z","git_url":"git://github.com/kennydo/artesia.git","ssh_url":"git@github.com:kennydo/artesia.git","clone_url":"https://github.com/kennydo/artesia.git","svn_url":"https://github.com/kennydo/artesia","homepage":null,"size":30,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"kennydo:master","ref":"master","sha":"13c4aea0b88f6a84e61203d7e05be5e22a3c408b","user":{"login":"kennydo","id":897349,"avatar_url":"https://avatars3.githubusercontent.com/u/897349?v=4","gravatar_id":"","url":"https://api.github.com/users/kennydo","html_url":"https://github.com/kennydo","followers_url":"https://api.github.com/users/kennydo/followers","following_url":"https://api.github.com/users/kennydo/following{/other_user}","gists_url":"https://api.github.com/users/kennydo/gists{/gist_id}","starred_url":"https://api.github.com/users/kennydo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennydo/subscriptions","organizations_url":"https://api.github.com/users/kennydo/orgs","repos_url":"https://api.github.com/users/kennydo/repos","events_url":"https://api.github.com/users/kennydo/events{/privacy}","received_events_url":"https://api.github.com/users/kennydo/received_events","type":"User","site_admin":false},"repo":{"id":133190341,"name":"artesia","full_name":"kennydo/artesia","owner":{"login":"kennydo","id":897349,"avatar_url":"https://avatars3.githubusercontent.com/u/897349?v=4","gravatar_id":"","url":"https://api.github.com/users/kennydo","html_url":"https://github.com/kennydo","followers_url":"https://api.github.com/users/kennydo/followers","following_url":"https://api.github.com/users/kennydo/following{/other_user}","gists_url":"https://api.github.com/users/kennydo/gists{/gist_id}","starred_url":"https://api.github.com/users/kennydo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kennydo/subscriptions","organizations_url":"https://api.github.com/users/kennydo/orgs","repos_url":"https://api.github.com/users/kennydo/repos","events_url":"https://api.github.com/users/kennydo/events{/privacy}","received_events_url":"https://api.github.com/users/kennydo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/kennydo/artesia","description":null,"fork":false,"url":"https://api.github.com/repos/kennydo/artesia","forks_url":"https://api.github.com/repos/kennydo/artesia/forks","keys_url":"https://api.github.com/repos/kennydo/artesia/keys{/key_id}","collaborators_url":"https://api.github.com/repos/kennydo/artesia/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/kennydo/artesia/teams","hooks_url":"https://api.github.com/repos/kennydo/artesia/hooks","issue_events_url":"https://api.github.com/repos/kennydo/artesia/issues/events{/number}","events_url":"https://api.github.com/repos/kennydo/artesia/events","assignees_url":"https://api.github.com/repos/kennydo/artesia/assignees{/user}","branches_url":"https://api.github.com/repos/kennydo/artesia/branches{/branch}","tags_url":"https://api.github.com/repos/kennydo/artesia/tags","blobs_url":"https://api.github.com/repos/kennydo/artesia/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/kennydo/artesia/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/kennydo/artesia/git/refs{/sha}","trees_url":"https://api.github.com/repos/kennydo/artesia/git/trees{/sha}","statuses_url":"https://api.github.com/repos/kennydo/artesia/statuses/{sha}","languages_url":"https://api.github.com/repos/kennydo/artesia/languages","stargazers_url":"https://api.github.com/repos/kennydo/artesia/stargazers","contributors_url":"https://api.github.com/repos/kennydo/artesia/contributors","subscribers_url":"https://api.github.com/repos/kennydo/artesia/subscribers","subscription_url":"https://api.github.com/repos/kennydo/artesia/subscription","commits_url":"https://api.github.com/repos/kennydo/artesia/commits{/sha}","git_commits_url":"https://api.github.com/repos/kennydo/artesia/git/commits{/sha}","comments_url":"https://api.github.com/repos/kennydo/artesia/comments{/number}","issue_comment_url":"https://api.github.com/repos/kennydo/artesia/issues/comments{/number}","contents_url":"https://api.github.com/repos/kennydo/artesia/contents/{+path}","compare_url":"https://api.github.com/repos/kennydo/artesia/compare/{base}...{head}","merges_url":"https://api.github.com/repos/kennydo/artesia/merges","archive_url":"https://api.github.com/repos/kennydo/artesia/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/kennydo/artesia/downloads","issues_url":"https://api.github.com/repos/kennydo/artesia/issues{/number}","pulls_url":"https://api.github.com/repos/kennydo/artesia/pulls{/number}","milestones_url":"https://api.github.com/repos/kennydo/artesia/milestones{/number}","notifications_url":"https://api.github.com/repos/kennydo/artesia/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/kennydo/artesia/labels{/name}","releases_url":"https://api.github.com/repos/kennydo/artesia/releases{/id}","deployments_url":"https://api.github.com/repos/kennydo/artesia/deployments","created_at":"2018-05-12T23:20:48Z","updated_at":"2018-05-26T07:29:18Z","pushed_at":"2018-05-27T05:45:49Z","git_url":"git://github.com/kennydo/artesia.git","ssh_url":"git@github.com:kennydo/artesia.git","clone_url":"https://github.com/kennydo/artesia.git","svn_url":"https://github.com/kennydo/artesia","homepage":null,"size":30,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":2,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/8"},"html":{"href":"https://github.com/kennydo/artesia/pull/8"},"issue":{"href":"https://api.github.com/repos/kennydo/artesia/issues/8"},"comments":{"href":"https://api.github.com/repos/kennydo/artesia/issues/8/comments"},"review_comments":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/8/comments"},"review_comment":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/kennydo/artesia/pulls/8/commits"},"statuses":{"href":"https://api.github.com/repos/kennydo/artesia/statuses/6859089319c6a9758fd93cf5f38a83d214a9ea97"}},"author_association":"COLLABORATOR"}}
{"actor":{"display_login":"Koshroy"}}