Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
R
rails_api_authentication
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open-source
rails_api_authentication
Commits
3fff1e87
Commit
3fff1e87
authored
Aug 02, 2017
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add oauth session controller
parent
c99b71f8
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
0 deletions
+49
-0
rails_api_authentication.rb
lib/rails_api_authentication.rb
+2
-0
acts_as_authentication_handler.rb
...ails_api_authentication/acts_as_authentication_handler.rb
+7
-0
authable.rb
lib/rails_api_authentication/authable.rb
+7
-0
oauth_session.rb
lib/rails_api_authentication/oauth_session.rb
+33
-0
No files found.
lib/rails_api_authentication.rb
View file @
3fff1e87
require
"rails_api_authentication/version"
require
"rails_api_authentication/user_error"
require
"rails_api_authentication/configuration"
require
"rails_api_authentication/auth_action"
require
"rails_api_authentication/auth_session"
require
"rails_api_authentication/oauth_session"
require
"rails_api_authentication/code_session"
require
"rails_api_authentication/auth_password"
require
"rails_api_authentication/auth_token"
...
...
lib/rails_api_authentication/acts_as_authentication_handler.rb
View file @
3fff1e87
...
...
@@ -12,6 +12,13 @@ module RailsApiAuthentication
auth_session
klass_sym
end
def
acts_as_oauth_session
(
klass_sym
)
include
RailsApiAuthentication
::
AuthAction
include
RailsApiAuthentication
::
OauthSession
auth_action
klass_sym
,
only:
[
:destroy
]
oauth_session
klass_sym
end
def
acts_as_auth_password
(
klass_sym
)
include
RailsApiAuthentication
::
AuthAction
include
RailsApiAuthentication
::
AuthPassword
...
...
lib/rails_api_authentication/authable.rb
View file @
3fff1e87
...
...
@@ -72,6 +72,13 @@ module RailsApiAuthentication
AuthToken
.
create
(
self
,
oauth_params
(
params
).
merge
({
oid:
user
.
id
})
)
end
def
oauth_login
(
oauth_type
,
oauth_id
)
user
=
self
.
find_or_create_by
oauth_type:
oauth_type
,
oauth_id:
oauth_id
AuthToken
.
create
(
self
,
{
oid:
user
.
id
,
oauth_type:
oauth_type
,
oauth_id:
oauth_id
}
)
end
def
auth!
(
request
)
token
=
request
.
env
[
"HTTP_
#{
self
.
to_s
.
upcase
}
_TOKEN"
]
||
request
.
env
[
"
#{
self
.
to_s
.
upcase
}
_TOKEN"
]
user
=
auth
(
token
)
...
...
lib/rails_api_authentication/oauth_session.rb
0 → 100644
View file @
3fff1e87
module
RailsApiAuthentication
module
OauthSession
extend
ActiveSupport
::
Concern
included
do
end
def
create
@auth_token
=
self
.
class
.
klass
.
oauth_login
(
session_params
.
delete
(
:oauth_type
),
session_params
.
delete
(
:oauth_id
))
render
json:
{
token:
@auth_token
.
token
},
status:
200
rescue
UserError
=>
e
render
json:
{
error:
e
.
message
},
status:
e
.
status
end
def
destroy
self
.
send
(
"current_
#{
self
.
class
.
klass_sym
}
"
)
&
.
logout
render
json:
{
message:
"logout successful"
},
status:
200
end
private
def
session_params
params
.
require
(
self
.
class
.
klass_sym
).
permit
(
:oauth_type
,
:oauth_id
)
end
module
ClassMethods
attr_reader
:klass
,
:klass_sym
def
oauth_session
klass_sym
@klass
=
klass_sym
.
to_s
.
camelize
.
constantize
@klass_sym
=
klass_sym
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment