Module: Sinatra::Auth::Github::Helpers

Defined in:
lib/sinatra/auth/github.rb

Instance Method Summary collapse

Instance Method Details

#_relative_url_for(path) ⇒ Object



142
143
144
# File 'lib/sinatra/auth/github.rb', line 142

def _relative_url_for(path)
  request.script_name + path
end

#authenticate!(*args) ⇒ Object



40
41
42
# File 'lib/sinatra/auth/github.rb', line 40

def authenticate!(*args)
  warden.authenticate!(*args)
end

#authenticated?(*args) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/sinatra/auth/github.rb', line 44

def authenticated?(*args)
  warden.authenticated?(*args)
end

#github_organization_access?(name) ⇒ Boolean

See if the user is a member of the named organization

name - the organization name

Returns: true if the user has access, false otherwise

Returns:

  • (Boolean)


99
100
101
# File 'lib/sinatra/auth/github.rb', line 99

def github_organization_access?(name)
  github_user.organization_member?(name)
end

#github_organization_authenticate!(name) ⇒ Object

Enforce user membership to the named organization if membership is publicized

name - the organization to test membership against

Returns an execution halt if the user is not a member of the named org



127
128
129
130
# File 'lib/sinatra/auth/github.rb', line 127

def github_organization_authenticate!(name)
  authenticate!
  halt([401, "Unauthorized User"]) unless github_organization_access?(name)
end

#github_public_organization_access?(name) ⇒ Boolean

See if the user is a public member of the named organization

name - the organization name

Returns: true if the user is public access, false otherwise

Returns:

  • (Boolean)


90
91
92
# File 'lib/sinatra/auth/github.rb', line 90

def github_public_organization_access?(name)
  github_user.publicized_organization_member?(name)
end

#github_public_organization_authenticate!(name) ⇒ Object

Enforce user membership to the named organization

name - the organization to test membership against

Returns an execution halt if the user is not a member of the named org



117
118
119
120
# File 'lib/sinatra/auth/github.rb', line 117

def github_public_organization_authenticate!(name)
  authenticate!
  halt([401, "Unauthorized User"]) unless github_public_organization_access?(name)
end

#github_raw_request(path) ⇒ Object

Send a V3 API GET request to path

path - the path on api.github.com to hit

Returns a rest client response object

Examples

github_raw_request("/user")
# => RestClient::Response


68
69
70
# File 'lib/sinatra/auth/github.rb', line 68

def github_raw_request(path)
  github_user.github_raw_request(path)
end

#github_request(path) ⇒ Object

Send a V3 API GET request to path and parse the response body

path - the path on api.github.com to hit

Returns a parsed JSON response

Examples

github_request("/user")
# => { 'login' => 'atmos', ... }


81
82
83
# File 'lib/sinatra/auth/github.rb', line 81

def github_request(path)
  github_user.github_request(path)
end

#github_team_access?(team_id) ⇒ Boolean

See if the user is a member of the team id

team_id - the team’s id

Returns: true if the user has access, false otherwise

Returns:

  • (Boolean)


108
109
110
# File 'lib/sinatra/auth/github.rb', line 108

def github_team_access?(team_id)
  github_user.team_member?(team_id)
end

#github_team_authenticate!(team_id) ⇒ Object

Enforce user membership to the team id

team_id - the team_id to test membership against

Returns an execution halt if the user is not a member of the team



137
138
139
140
# File 'lib/sinatra/auth/github.rb', line 137

def github_team_authenticate!(team_id)
  authenticate!
  halt([401, "Unauthorized User"]) unless github_team_access?(team_id)
end

#github_userObject

The authenticated user object

Supports a variety of methods, name, full_name, email, etc



55
56
57
# File 'lib/sinatra/auth/github.rb', line 55

def github_user
  warden.user
end

#logout!Object



48
49
50
# File 'lib/sinatra/auth/github.rb', line 48

def logout!
  warden.logout
end

#wardenObject



36
37
38
# File 'lib/sinatra/auth/github.rb', line 36

def warden
  env['warden']
end