Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
05fefe4a
Commit
05fefe4a
authored
9 months ago
by
Jan-Hendrik Willms
Committed by
David Siegfried
9 months ago
Browse files
Options
Downloads
Patches
Plain Diff
remove oauth1 from jsonapi, fixes #4204
Closes #4204 Merge request
studip/studip!3031
parent
addf6e2d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
lib/classes/JsonApi/Middlewares/Auth/OAuth1Strategy.php
+0
-114
0 additions, 114 deletions
lib/classes/JsonApi/Middlewares/Auth/OAuth1Strategy.php
lib/classes/JsonApi/Middlewares/Authentication.php
+0
-1
0 additions, 1 deletion
lib/classes/JsonApi/Middlewares/Authentication.php
with
0 additions
and
115 deletions
lib/classes/JsonApi/Middlewares/Auth/OAuth1Strategy.php
deleted
100644 → 0
+
0
−
114
View file @
addf6e2d
<?php
namespace
JsonApi\Middlewares\Auth
;
use
Psr\Http\Message\ResponseInterface
as
Response
;
use
Psr\Http\Message\ServerRequestInterface
as
Request
;
class
OAuth1Strategy
implements
Strategy
{
/** @var callable */
protected
$authenticator
;
/** @var Request */
protected
$request
;
/** @var ?\User */
protected
$user
;
/**
* @param callable $authenticator
*/
public
function
__construct
(
Request
$request
,
$authenticator
)
{
$this
->
request
=
$request
;
$this
->
authenticator
=
$authenticator
;
\OAuthStore
::
instance
(
'PDO'
,
[
'conn'
=>
\DBManager
::
get
()]);
}
public
function
check
()
{
return
!
is_null
(
$this
->
user
());
}
public
function
user
()
{
if
(
!
is_null
(
$this
->
user
))
{
return
$this
->
user
;
}
$this
->
user
=
$this
->
detect
();
return
$this
->
user
;
}
public
function
addChallenge
(
Response
$response
)
{
return
$response
;
//->withHeader('WWW-Authenticate', sprintf('Basic realm="%s"', 'Stud.IP JSON-API'));
}
private
function
detect
():
?
\User
{
if
(
!
\OAuthRequestVerifier
::
requestIsSigned
())
{
return
null
;
}
$uri
=
(
string
)
$this
->
request
->
getUri
();
$method
=
$this
->
request
->
getMethod
();
if
(
'GET'
===
strtoupper
((
$method
)))
{
$parameters
=
(
array
)
$this
->
request
->
getQueryParams
();
}
elseif
(
'POST'
===
strtoupper
((
$method
)))
{
$parameters
=
(
array
)
$this
->
request
->
getParsedBody
();
}
else
{
$parameters
=
[];
}
$parameters
=
$this
->
getParamsFromAuthorizationHeader
(
$this
->
request
,
$parameters
);
$req
=
new
\OAuthRequestVerifier
(
$uri
,
$method
,
$parameters
);
// Check oauth timestamp and deny access if timestamp is outdated
if
(
$req
->
getParam
(
'oauth_timestamp'
)
<
strtotime
(
'-6 hours'
))
{
return
null
;
}
$result
=
$req
->
verifyExtended
(
'access'
);
$query
=
'SELECT user_id FROM api_oauth_user_mapping WHERE oauth_id = ?'
;
$statement
=
\DBManager
::
get
()
->
prepare
(
$query
);
$statement
->
execute
([
$result
[
'user_id'
]]);
if
(
!
$userId
=
$statement
->
fetchColumn
())
{
return
null
;
}
/** @var \User */
return
\User
::
find
(
$userId
);
}
private
function
getParamsFromAuthorizationHeader
(
Request
$request
,
array
$params
):
array
{
if
(
$request
->
hasHeader
(
'Authorization'
))
{
$auth
=
$request
->
getHeaderLine
(
'Authorization'
);
if
(
0
==
strncasecmp
(
$auth
,
'OAuth'
,
4
))
{
foreach
(
explode
(
','
,
substr
(
$auth
,
6
))
as
$v
)
{
if
(
!
strpos
(
$v
,
'='
))
{
continue
;
}
$v
=
trim
(
$v
);
list
(
$name
,
$value
)
=
explode
(
'='
,
$v
,
2
);
if
(
!
empty
(
$value
)
&&
'"'
==
$value
[
0
]
&&
'"'
==
substr
(
$value
,
-
1
))
{
$value
=
substr
(
substr
(
$value
,
1
),
0
,
-
1
);
}
if
(
0
!=
strcasecmp
(
$name
,
'realm'
))
{
$params
[
$name
]
=
$value
;
}
}
}
}
return
$params
;
}
}
This diff is collapsed.
Click to expand it.
lib/classes/JsonApi/Middlewares/Authentication.php
+
0
−
1
View file @
05fefe4a
...
...
@@ -107,7 +107,6 @@ class Authentication
'session'
=>
new
Auth\SessionStrategy
(),
'basic'
=>
new
Auth\HttpBasicAuthStrategy
(
$request
,
$this
->
authenticator
),
'oauth2'
=>
new
Auth\OAuth2Strategy
(
$request
,
$this
->
authenticator
),
'oauth1'
=>
new
Auth\OAuth1Strategy
(
$request
,
$this
->
authenticator
),
];
foreach
(
$this
->
excluded_strategies
as
$strategy
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment