Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
steering
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
AURA
steering
Commits
d479a9fd
Commit
d479a9fd
authored
3 years ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
Add --client_id and --client_secret as optional arguments
parent
3f0698fc
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
program/management/commands/create_oidc_client.py
+36
-29
36 additions, 29 deletions
program/management/commands/create_oidc_client.py
with
36 additions
and
29 deletions
program/management/commands/create_oidc_client.py
+
36
−
29
View file @
d479a9fd
...
...
@@ -12,6 +12,10 @@ class Command(BaseCommand):
help
=
'
A label that you associate with this client
'
)
parser
.
add_argument
(
'
client_type
'
,
type
=
str
,
choices
=
[
'
public
'
,
'
confidential
'
],
help
=
'
The type of client can be either public or confidential
'
)
parser
.
add_argument
(
'
--client-id
'
,
type
=
int
,
dest
=
'
client_id
'
,
action
=
'
store
'
,
help
=
'
The client ID
'
)
parser
.
set_defaults
(
client_id
=
None
)
parser
.
add_argument
(
'
--client-secret
'
,
type
=
str
,
dest
=
'
client_secret
'
,
action
=
'
store
'
,
help
=
'
The client secret
'
)
parser
.
set_defaults
(
client_secret
=
None
)
parser
.
add_argument
(
'
--no-require-consent
'
,
dest
=
'
require_consent
'
,
action
=
'
store_false
'
,
help
=
'
By default user consent is required. Use this to skip user consent.
'
)
parser
.
add_argument
(
'
--no-reuse-consent
'
,
dest
=
'
reuse_consent
'
,
action
=
'
store_false
'
,
...
...
@@ -31,29 +35,32 @@ class Command(BaseCommand):
'
(and the client secret in case of confidential clients).
'
)
parser
.
set_defaults
(
id_only
=
False
)
def
handle
(
self
,
*
args
,
**
options
):
# generate a new client ID and secret
client_id
=
False
counter
=
0
while
not
client_id
:
client_id
=
random
.
randint
(
100000
,
999999
)
counter
+=
1
if
counter
>
10000
:
raise
CommandError
(
'
Could not find a free client_id. Already
'
+
\
'
tried 10000 times. There seems to be something seriously
'
+
\
'
wrong with your setup. Please inspect manually.
'
)
try
:
Client
.
objects
.
get
(
client_id
=
client_id
)
except
Client
.
DoesNotExist
:
pass
else
:
client_id
=
False
if
options
[
'
client_id
'
]
and
options
[
'
client_secret
'
]:
client_id
=
options
[
'
client_id
'
]
client_secret
=
options
[
'
client_secret
'
]
else
:
# generate a new client ID and secret
client_id
=
False
counter
=
0
while
not
client_id
:
client_id
=
random
.
randint
(
100000
,
999999
)
counter
+=
1
if
counter
>
10000
:
raise
CommandError
(
'
Could not find a free client_id. Already
'
+
\
'
tried 10000 times. There seems to be something seriously
'
+
\
'
wrong with your setup. Please inspect manually.
'
)
try
:
Client
.
objects
.
get
(
client_id
=
client_id
)
except
Client
.
DoesNotExist
:
pass
else
:
client_id
=
False
client_secret
=
''
if
options
[
'
client_type
'
]
==
'
confidential
'
:
client_secret
=
''
.
join
(
random
.
SystemRandom
().
choice
(
string
.
ascii_letters
+
string
.
digits
)
for
_
in
range
(
32
))
show_results
=
options
[
'
client_id
'
]
is
None
and
options
[
'
client_secret
'
]
is
None
# initialize lists if no option was provided
if
options
[
'
redirect_uri
'
]
is
None
:
options
[
'
redirect_uri
'
]
=
[]
...
...
@@ -62,7 +69,7 @@ class Command(BaseCommand):
if
options
[
'
scope
'
]
is
None
:
options
[
'
scope
'
]
=
[]
if
not
options
[
"
id_only
"
]:
if
not
options
[
"
id_only
"
]
and
show_results
:
self
.
stdout
.
write
(
f
'
Creating client with name
{
options
[
"
name
"
]
}
'
)
try
:
c
=
Client
(
...
...
@@ -80,7 +87,6 @@ class Command(BaseCommand):
raise
CommandError
(
'
Could not create an OpenID connect client
'
+
\
f
'
due to the following error:
{
sys
.
exc_info
()
}
'
)
if
options
[
'
response_types
'
]:
try
:
for
r_value
in
options
[
'
response_types
'
]:
...
...
@@ -90,12 +96,13 @@ class Command(BaseCommand):
raise
CommandError
(
'
Client was stored, but could not set response_types
'
+
\
f
'
due to the following error:
{
sys
.
exc_info
()
}
'
)
if
options
[
"
id_only
"
]:
if
options
[
'
client_type
'
]
==
'
confidential
'
:
self
.
stdout
.
write
(
f
'
{
c
.
client_id
}
{
c
.
client_secret
}
'
)
if
show_results
:
if
options
[
"
id_only
"
]:
if
options
[
'
client_type
'
]
==
'
confidential
'
:
self
.
stdout
.
write
(
f
'
{
c
.
client_id
}
{
c
.
client_secret
}
'
)
else
:
self
.
stdout
.
write
(
f
'
{
c
.
client_id
}
'
)
else
:
self
.
stdout
.
write
(
f
'
{
c
.
client_id
}
'
)
else
:
self
.
stdout
.
write
(
f
'
Successfully created new OIDC client, with ID:
{
c
.
client_id
}
'
)
if
options
[
'
client_type
'
]
==
'
confidential
'
:
self
.
stdout
.
write
(
f
'
The secret for this confidential client is:
{
c
.
client_secret
}
'
)
self
.
stdout
.
write
(
f
'
Successfully created new OIDC client, with ID:
{
c
.
client_id
}
'
)
if
options
[
'
client_type
'
]
==
'
confidential
'
:
self
.
stdout
.
write
(
f
'
The secret for this confidential client is:
{
c
.
client_secret
}
'
)
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