-
Notifications
You must be signed in to change notification settings - Fork 378
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set up ory kratos, add identity admin api #1460
Set up ory kratos, add identity admin api #1460
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1460 +/- ##
==========================================
+ Coverage 15.49% 15.61% +0.11%
==========================================
Files 1143 1148 +5
Lines 109672 109930 +258
==========================================
+ Hits 16995 17166 +171
- Misses 91020 91051 +31
- Partials 1657 1713 +56
|
db847bd
to
ea72ec5
Compare
ea72ec5
to
6dadb3b
Compare
@@ -86,6 +86,10 @@ func freezeUser(w http.ResponseWriter, r *http.Request) { | |||
} | |||
|
|||
func handleFreezeUser(userID, operatorID string, token ucauth.OAuthToken) error { | |||
if token.TokenType == ucauth.OryCompatibleClientId { | |||
return ucauth.ChangeUserState(token.AccessToken, userID, "inactive") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic value is not good: "inactive"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
// TODO: password oidc | ||
if token.TokenType == ucauth.OryCompatibleClientId { | ||
return &listLoginTypeResult{ | ||
RegistryType: []string{"email"}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -87,6 +87,10 @@ func unfreezeUser(w http.ResponseWriter, r *http.Request) { | |||
} | |||
|
|||
func handleUnfreezeUser(userID, operatorID string, token ucauth.OAuthToken) error { | |||
if token.TokenType == ucauth.OryCompatibleClientId { | |||
return ucauth.ChangeUserState(token.AccessToken, userID, "active") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/ucauth/identity_paging.go
Outdated
cnt++ | ||
} | ||
} | ||
if cnt >= 10 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why only 10 matched users?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed
if start > len(i) { | ||
return nil | ||
} | ||
end := start + pageSize |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's better to ensure pageSize > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,52 @@ | |||
{ | |||
"$id": "https://schemas.ory.sh/presets/kratos/quickstart/email-password/identity.schema.json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like it's an example value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
pkg/ucauth/kratos/kratos.yml
Outdated
@@ -0,0 +1,80 @@ | |||
version: v0.4.6-alpha.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
version is too low?
base_url: http://kratos:4434/ | ||
|
||
selfservice: | ||
default_browser_return_url: http://one.erda.local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be replace to related path, not static domain
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Config source validation has been improved in later ory/kratos version. we are not using it. it can be replaced by env SELFSERVICE_DEFAULT_BROWSER_RETURN_URL .
pkg/ucauth/model.go
Outdated
Mobile: u.Phone, | ||
Email: u.Email, | ||
Enabled: true, | ||
Locked: u.State == "inactive", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
magic value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -11,7 +11,7 @@ serve: | |||
base_url: http://kratos:4434/ | |||
|
|||
selfservice: | |||
default_browser_return_url: / | |||
default_browser_return_url: http://one.erda.local |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do not user hard-coded domain
6dadb3b
to
1f5f9cb
Compare
@@ -0,0 +1,7 @@ | |||
CREATE TABLE `kratos_uc_userid_mapping` ( | |||
`id` varchar(50) NOT NULL COMMENT 'uc userid', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change id
to uc_user_id
.
add index for both uc_user_id
and user_id
separately.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add user_id index
func (client *DBClient) InsertMapping(userID, uuid, hash string) error { | ||
return client.Transaction(func(tx *gorm.DB) error { | ||
sql := fmt.Sprintf("UPDATE identity_credentials SET config = JSON_SET(config, '$.hashed_password', ?) WHERE identity_id = ?") | ||
if err := client.Exec(sql, hash, uuid).Error; err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
client.Exec
should be tx.Exec
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
absolutely
@@ -244,6 +246,12 @@ func WithFileSvc(svc *filesvc.FileService) Option { | |||
} | |||
} | |||
|
|||
func WithMigrationSvc(svc *migration.Migration) Option { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad pkg. Just put it under uc service.
@@ -433,5 +449,6 @@ func (e *Endpoints) Routes() []httpserver.Endpoint { | |||
{Path: "/api/users", Method: http.MethodGet, Handler: e.ListUser}, | |||
{Path: "/api/users/current", Method: http.MethodGet, Handler: e.GetCurrentUser}, | |||
{Path: "/api/users/actions/search", Method: http.MethodGet, Handler: e.SearchUser}, | |||
{Path: "/api/users/userID", Method: http.MethodGet, Handler: e.GetUcUserID}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bad path. No uppercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
modules/core-services/initialize.go
Outdated
return | ||
} | ||
for i := 0; i < 3; i++ { | ||
if ep.UcSvc().MigrationReady() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The condition maybe inverse?
modules/core-services/initialize.go
Outdated
if !conf.OryEnabled() { | ||
return | ||
} | ||
for i := 0; i < 3; i++ { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 3
@@ -0,0 +1,20 @@ | |||
package model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
filename should be uc_migration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
modules/openapi/conf/conf.go
Outdated
} | ||
|
||
// TODO change return url | ||
func OryLogoutURL() string { | ||
return "/.ory/kratos/public/self-service/browser/flows/logout" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this url correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will remove deprecated configs
20f8a5e
to
79bc038
Compare
79bc038
to
d3a43be
Compare
@@ -254,6 +262,14 @@ func (e *Endpoints) GetLocale(request *http.Request) *i18n.LocaleResource { | |||
return e.bdl.GetLocaleByRequest(request) | |||
} | |||
|
|||
func (e *Endpoints) MigrationSvc() *migration.Migration { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
split true user service.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
lifespan: 10m | ||
|
||
registration: | ||
lifespan: 10m | ||
ui_url: /uc/auth/registration | ||
ui_url: http://one.erda.local/uc/auth/registration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add comment in code. Not just on conversation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
/approve |
/cherry-pick release/1.3 |
* Set up ory kratos, add identity admin api * Code refactor, comment in kratos config
What type of this PR
feature
What this PR does / why we need it:
the first step in replacing uc component
Specified Reviewers:
/assign @Effet