Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
STS
Manage
Activity
Members
Labels
Plan
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Coscine
backend
apis
STS
Merge requests
!104
BREAKING: New Login Behavior for UIv2 (coscine/issues#1833)
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
BREAKING: New Login Behavior for UIv2 (coscine/issues#1833)
Issue/1833-newLogin
into
uiv2
Overview
0
Commits
1
Pipelines
2
Changes
6
Merged
Benedikt Heinrichs
requested to merge
Issue/1833-newLogin
into
uiv2
3 years ago
Overview
0
Commits
1
Pipelines
2
Changes
6
Expand
0
0
Merge request reports
Compare
uiv2
uiv2 (base)
and
latest version
latest version
ac03dac6
1 commit,
3 years ago
6 files
+
52
−
107
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
6
Search (e.g. *.vue) (Ctrl+P)
src/STS/Controllers/HomeController.cs
+
36
−
65
Options
using
System
;
using
System.Security.Claims
;
using
Microsoft.AspNetCore.Mvc
;
using
Microsoft.AspNetCore.Http.Features
;
using
Microsoft.AspNetCore.Http
;
using
Coscine.Api.STS.Utils
;
using
Coscine.ApiCommons
;
using
Coscine.Database.Models
;
using
System.Linq
;
using
Coscine.ActiveDirectory
;
using
System.Net.Http
;
using
System.Web
;
using
Newtonsoft.Json
;
using
System.Text
;
using
System.Collections.Generic
;
using
Coscine.JwtHandler
;
namespace
Coscine.Api.STS.Controllers
{
public
class
HomeController
:
Controller
{
private
static
HttpClient
_httpClient
=
new
HttpClient
();
private
static
readonly
HttpClient
_httpClient
=
new
();
public
const
string
Action
=
"wa"
;
public
const
string
SignInString
=
"wsignin1.0"
;
public
const
string
SignOutString
=
"wsignout1.0"
;
//[Authorize]
[
Route
(
"/"
)]
public
ActionResult
Index
()
{
if
(
User
.
Identity
.
IsAuthenticated
)
{
var
res
=
Request
.
Query
[
Action
];
if
(
res
.
Count
>
0
)
{
var
action
=
Request
.
Query
[
Action
][
0
];
if
(
action
==
SignInString
)
{
var
userIdString
=
User
.
Identity
.
Name
;
var
userId
=
new
Guid
(
userIdString
);
var
userIdString
=
User
.
Identity
.
Name
;
var
userId
=
new
Guid
(
userIdString
);
if
(
Request
.
Cookies
.
ContainsKey
(
MergeController
.
MERGETOKENKEY
))
{
string
mergeCallbackUrl
=
UrlGenerator
.
MergeCallbackRedirectUrl
();
return
Redirect
(
mergeCallbackUrl
);
}
if
(
Request
.
Cookies
.
ContainsKey
(
MergeController
.
MERGETOKENKEY
))
{
string
mergeCallbackUrl
=
UrlGenerator
.
MergeCallbackRedirectUrl
();
return
Redirect
(
mergeCallbackUrl
);
}
if
(!
AreTOSAccepted
(
userId
))
{
string
tosUrl
=
UrlGenerator
.
GetTOSUrl
(
Request
,
userIdString
);
return
Redirect
(
tosUrl
);
}
if
(!
AreTOSAccepted
(
userId
))
{
string
tosUrl
=
UrlGenerator
.
GetTOSUrl
(
Request
,
userIdString
);
return
Redirect
(
tosUrl
);
}
var
reqFeature
=
HttpContext
.
Features
.
Get
<
IHttpRequestFeature
>();
var
rawTarget
=
reqFeature
.
RawTarget
;
var
formData
=
ProcessSignIn
(
new
Uri
(
Program
.
MainUrl
+
rawTarget
),
User
);
return
new
ContentResult
()
{
Content
=
formData
,
ContentType
=
"text/html"
};
}
ProcessSignIn
(
User
);
var
redirects
=
Request
.
Query
[
"redirect"
];
if
(
redirects
.
Count
>
0
)
{
ViewBag
.
Redirect
=
redirects
[
0
];
}
else
{
ViewBag
.
Redirect
=
"/"
;
}
var
dictionary
=
new
Dictionary
<
string
,
string
>
{
{
"UserId"
,
userId
.
ToString
()
}
};
var
jwtHandler
=
new
JWTHandler
(
Program
.
Configuration
);
ViewBag
.
Token
=
jwtHandler
.
GenerateJwtToken
(
dictionary
);
// STS Exit Point
return
View
();
}
string
loginUrl
=
UrlGenerator
.
GetLoginUrl
(
Request
);
return
Redirect
(
loginUrl
);
@@ -71,41 +71,12 @@ namespace Coscine.Api.STS.Controllers
&&
tosAcceptedList
.
Any
((
entry
)
=>
entry
.
Version
==
currentTos
);
}
private
string
ProcessSignIn
(
Uri
url
,
ClaimsPrincipal
user
)
private
void
ProcessSignIn
(
ClaimsPrincipal
user
)
{
var
userModel
=
new
UserModel
();
var
realUser
=
userModel
.
GetById
(
Guid
.
Parse
(
user
.
Identity
.
Name
));
ADHandler
.
AddUser
(
realUser
,
Program
.
Configuration
);
var
userObject
=
new
{
realUser
.
DisplayName
,
realUser
.
Id
,
realUser
.
EmailAddress
};
var
signInInstance
=
new
{
User
=
new
{
Claims
=
user
.
Claims
,
Identities
=
user
.
Identities
,
Identitiy
=
user
.
Identity
},
UserObject
=
userObject
};
var
uri
=
$"http://localhost:
{
Program
.
Configuration
.
GetStringAndWait
(
"coscine/apis/Coscine.Api.LegacySTS/port"
)}
/sts/processSignIn/
{
HttpUtility
.
UrlEncode
(
url
.
ToString
())}
/
{
HttpUtility
.
UrlEncode
(
Request
.
Host
.
Value
)}
"
;
var
content
=
new
StringContent
(
JsonConvert
.
SerializeObject
(
signInInstance
,
Formatting
.
Indented
,
new
JsonSerializerSettings
{
ReferenceLoopHandling
=
ReferenceLoopHandling
.
Ignore
}),
Encoding
.
UTF8
,
"application/json"
);
var
result
=
_httpClient
.
PostAsync
(
uri
,
content
).
Result
;
return
result
.
Content
.
ReadAsStringAsync
().
Result
;
}
}
}
Loading