Skip to content

Commit

Permalink
added new path for disposable tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
elenik72 committed Jul 17, 2024
1 parent 922ba7a commit c9fd101
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/client/AutherClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class AutherClient {
#REVOKE_PATH = "/tokens/revoke"
#REFRESH_PATH = "/tokens/refresh"
#LOGIN_PATH = "/login"
#DISPOSABLE_TOKEN_PATH = "/tokens/disposable"

constructor ({ redirectUri, autherUrl, http, appcode, logger }) {
this.redirectUri = redirectUri
Expand Down Expand Up @@ -124,4 +125,16 @@ export class AutherClient {

this.#scheduleTokensRefreshing({ getTokens, saveTokens })
}

fetchDisposableTokensById = async ({ id }) => {
if (!id) {
throw new Error("invalid.auther_id")
}

return await this.http({

Check failure on line 134 in src/client/AutherClient.js

View workflow job for this annotation

GitHub Actions / lint

Redundant use of `await` on a return value
path: this.#DISPOSABLE_TOKEN_PATH,
query: { id },
method: "GET",
})
}
}
17 changes: 12 additions & 5 deletions src/lib/http.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export const doFetch = url => params => {
const { path, body, method = "POST", headers = "" } = params
export const doFetch = baseUrl => params => {
const { path, body, query, method = "POST", headers = "" } = params

const buildHeaders = () => {
const defaultHeaders = {
Expand All @@ -19,11 +19,18 @@ export const doFetch = url => params => {
return JSON.stringify(body)
}

const buildUrl = () => {
return new URL(path, url).toString()
const buildUrl = (query) => {

Check failure on line 22 in src/lib/http.js

View workflow job for this annotation

GitHub Actions / lint

Unexpected parentheses around single function argument
const url = new URL(path, baseUrl)

if (query) {
const params = new URLSearchParams(query)
url.search = params.toString()
}

Check failure on line 29 in src/lib/http.js

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces not allowed
return url.toString()
}

const requestUrl = buildUrl()
const requestUrl = buildUrl(query)
const requestHeaders = buildHeaders()
const requestBody = buildBody()

Expand Down

0 comments on commit c9fd101

Please sign in to comment.