Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
F
Frontend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Package Registry
Model registry
Operate
Terraform modules
Monitor
Service Desk
Analyze
Contributor analytics
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
HUB Terra
SMS
Frontend
Commits
9cd09f98
Commit
9cd09f98
authored
4 years ago
by
Nils Brinckmann
Browse files
Options
Downloads
Patches
Plain Diff
Strategy to send the id token for every sms request
parent
4a8572c1
No related branches found
No related tags found
1 merge request
!78
Resolve "Add JWT Token from OIDC for post, patch & delete requests"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
services/Api.ts
+27
-8
27 additions, 8 deletions
services/Api.ts
services/sms/ContactApi.ts
+2
-16
2 additions, 16 deletions
services/sms/ContactApi.ts
with
29 additions
and
24 deletions
services/Api.ts
+
27
−
8
View file @
9cd09f98
...
...
@@ -73,7 +73,9 @@ export class Api {
constructor
(
getIdToken
:
()
=>
string
|
null
,
smsBaseUrl
:
string
|
undefined
=
SMS_BASE_URL
,
cvBaseUrl
:
string
|
undefined
=
CV_BASE_URL
)
{
smsBaseUrl
:
string
|
undefined
=
SMS_BASE_URL
,
cvBaseUrl
:
string
|
undefined
=
CV_BASE_URL
)
{
// here we can set settings for all the sms api calls
const
smsConfig
:
AxiosRequestConfig
=
{
// for the SMS Backend we need the explicit vnd.api+json
...
...
@@ -81,18 +83,19 @@ export class Api {
'
Content-Type
'
:
'
application/vnd.api+json
'
}
}
// For the sms we also want to send the id token, if we currently
// have one in the store.
this
.
_contactApi
=
new
ContactApi
(
this
.
createAxios
(
smsBaseUrl
,
'
/contacts
'
,
smsConfig
)
,
getIdToken
this
.
createAxios
(
smsBaseUrl
,
'
/contacts
'
,
smsConfig
,
getIdToken
)
)
this
.
_platformApi
=
new
PlatformApi
(
this
.
createAxios
(
smsBaseUrl
,
'
/platforms
'
,
smsConfig
)
this
.
createAxios
(
smsBaseUrl
,
'
/platforms
'
,
smsConfig
,
getIdToken
)
)
this
.
_deviceApi
=
new
DeviceApi
(
this
.
createAxios
(
smsBaseUrl
,
'
/devices
'
,
smsConfig
)
this
.
createAxios
(
smsBaseUrl
,
'
/devices
'
,
smsConfig
,
getIdToken
)
)
this
.
_configurationApi
=
new
ConfigurationApi
(
this
.
createAxios
(
smsBaseUrl
,
'
/configurations
'
,
smsConfig
)
this
.
createAxios
(
smsBaseUrl
,
'
/configurations
'
,
smsConfig
,
getIdToken
)
)
this
.
_configurationStatesApi
=
new
ConfigurationStatusApi
()
...
...
@@ -136,12 +139,28 @@ export class Api {
this
.
_projectApi
=
new
ProjectApi
()
}
private
createAxios
(
baseUrl
:
string
|
undefined
,
path
:
string
,
baseConfig
:
AxiosRequestConfig
):
AxiosInstance
{
private
createAxios
(
baseUrl
:
string
|
undefined
,
path
:
string
,
baseConfig
:
AxiosRequestConfig
,
getIdToken
?:
()
=>
(
string
|
null
)
):
AxiosInstance
{
const
config
=
{
...
baseConfig
,
baseURL
:
baseUrl
+
path
}
return
axios
.
create
(
config
)
const
instance
=
axios
.
create
(
config
)
// If we have a function to query our id tokens on the time of the request
// we want to use it here.
if
(
getIdToken
)
{
instance
.
interceptors
.
request
.
use
((
config
)
=>
{
const
idToken
=
getIdToken
()
// But it can be that we are not logged in, so that our idToken is null.
// So in this case, we don't send the id token with the request.
if
(
idToken
)
{
// But once we have it, we want to send it with.
config
.
headers
.
Authorization
=
'
Bearer
'
+
idToken
}
return
config
})
}
return
instance
}
get
devices
():
DeviceApi
{
...
...
This diff is collapsed.
Click to expand it.
services/sms/ContactApi.ts
+
2
−
16
View file @
9cd09f98
...
...
@@ -37,12 +37,10 @@ import { IPaginationLoader, FilteredPaginationedLoader } from '@/utils/Paginated
export
class
ContactApi
{
private
axiosApi
:
AxiosInstance
private
getIdToken
:
()
=>
string
|
null
private
serializer
:
ContactSerializer
constructor
(
axiosInstance
:
AxiosInstance
,
getIdToken
:
()
=>
string
|
null
)
{
constructor
(
axiosInstance
:
AxiosInstance
)
{
this
.
axiosApi
=
axiosInstance
this
.
getIdToken
=
getIdToken
this
.
serializer
=
new
ContactSerializer
()
}
...
...
@@ -58,19 +56,7 @@ export class ContactApi {
}
deleteById
(
id
:
string
):
Promise
<
void
>
{
let
accessHeaders
=
{}
const
token
=
this
.
getIdToken
()
if
(
token
)
{
accessHeaders
=
{
Authorization
:
'
Bearer
'
+
token
}
}
return
this
.
axiosApi
.
delete
<
string
,
void
>
(
id
,
{
headers
:
{
...
accessHeaders
}
})
return
this
.
axiosApi
.
delete
<
string
,
void
>
(
id
)
}
save
(
contact
:
Contact
)
{
...
...
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