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
c5640dd9
Commit
c5640dd9
authored
7 years ago
by
liyijie
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add oauth relation with token
parent
1e9cf58f
master
…
lan/change_user_error_code
lan/ttl
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
6 deletions
+37
-6
auth_token.rb
lib/rails_api_authentication/auth_token.rb
+1
-2
authable.rb
lib/rails_api_authentication/authable.rb
+19
-4
oauth_session.rb
lib/rails_api_authentication/oauth_session.rb
+17
-0
No files found.
lib/rails_api_authentication/auth_token.rb
View file @
c5640dd9
...
...
@@ -27,4 +27,4 @@ module RailsApiAuthentication
super
params
end
end
end
\ No newline at end of file
end
This diff is collapsed.
Click to expand it.
lib/rails_api_authentication/authable.rb
View file @
c5640dd9
...
...
@@ -73,10 +73,25 @@ module RailsApiAuthentication
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
}
)
if
@oauth_only
.
present?
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
}
)
else
auth
=
AuthToken
.
find
(
oauth_type:
oauth_type
,
oauth_id:
oauth_id
)
&
.
first
user
=
self
.
find_by
(
id:
auth
.
oid
)
raise
(
UserError
.
new
(
401
,
'-1'
,
'Unauthorized'
))
unless
user
.
present?
end
end
def
oauth_relate
(
token
,
oauth_type
,
oauth_id
)
auth
=
AuthToken
.
find
(
token:
token
)
&
.
first
if
auth
.
present?
&&
self
.
find_by
(
id:
auth
.
oid
).
present?
auth
.
update
(
oauth_type:
oauth_type
,
oauth_id:
oauth_id
)
else
raise
(
UserError
.
new
(
401
,
'-1'
,
'Unauthorized'
))
unless
user
.
present?
end
end
def
auth!
(
request
)
...
...
This diff is collapsed.
Click to expand it.
lib/rails_api_authentication/oauth_session.rb
View file @
c5640dd9
...
...
@@ -12,11 +12,28 @@ module RailsApiAuthentication
render
json:
{
error:
e
.
message
},
status:
e
.
status
end
def
update
@auth_token
=
self
.
class
.
klass
.
oauth_relate
(
session_relate_params
.
delete
(
:token
),
session_relate_params
.
delete
(
:oauth_type
),
session_relate_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
def
session_relate_params
params
.
require
(
self
.
class
.
klass_sym
).
permit
(
:oauth_type
,
:oauth_id
,
:token
)
end
def
session_params
params
.
require
(
self
.
class
.
klass_sym
).
permit
(
:oauth_type
,
:oauth_id
)
end
...
...
This diff is collapsed.
Click to expand it.
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