Class ::xo::oauth::GitHub (public)
::nx::Class ::xo::oauth::GitHub
Defined in packages/xooauth/tcl/authorize-procs.tcl
Tailored OAuth handler for GitHub
- Testcases:
- No testcase defined.
Source code: :property {pretty_name "GitHub"} :property {base_url https://github.com/login/oauth} :property {responder_url /oauth/github-login-handler} :property {scope {read:user user:email}} :method get_api_data {access_token} { set data [ns_http run -headers [ns_set create query Authorization "Bearer $access_token"] https://api.github.com/user] if {[dict get $data status] ne 200} { dict set result error oacs-cant_get_api_data dict set result error_description $data } else { set json_body [dict get $data body] dict set result claims [:json_to_dict $json_body] } ns_log notice "[self] get_api_data $access_token returns $result" return $result } :public method get_user_data { -token {-required_fields { {email email} {name name} }} } { # # Get user data based on the temporary code (passed via # "-token") provided by GitHub. First, convert the # temporary code into an access_token, and use this to get # the user data. # set data [:redeem_code $token] ns_log notice "[self] redeem_code returned keys: [lsort [dict keys $data]]" set result $data if {[dict exists $data access_token]} { # # When we received the access_token, we have no error # so far. # set access_token [dict get $data access_token] #ns_log notice "[self] redeemed form data: $access_token" set result [:get_api_data $access_token] ns_log notice "[self] get_user_data: get_api_data contains error:" [dict exists $result error] if {![dict exists $result error]} { set data [:get_required_fields -claims [dict get $result claims] -mapped_fields { {email email} {name name} }] if {[dict exists $data error]} { set result [dict merge $data $result] } else { set result [dict merge $result [dict get $data fields]] # # We have still to split up "name" into its # components, since GitHub does not provide # the exactly needed fields. Actually, we need # this just for creating a new user_id, so it # might not be always needed. # set first_names [join [lrange [dict get $result name] 0 end-1] " "] set last_name [lindex [dict get $result name] end] dict set result first_names $first_names dict set result last_name $last_name } } } ns_log notice "[self] get_user_data returns $result" return $result } :public method logout_url { {-return_url ""} } { # # Returns the URL for logging out. E.g., GitHub has no # logout, so provide simply a redirect URL (maybe, we # should logout from the application?) # return $return_url }XQL Not present: Generic, PostgreSQL, Oracle