Skip to content
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

Add support for "Bearer Authentication" in operations #62

Closed
bennycode opened this issue Aug 7, 2019 · 3 comments · Fixed by #63
Closed

Add support for "Bearer Authentication" in operations #62

bennycode opened this issue Aug 7, 2019 · 3 comments · Fixed by #63

Comments

@bennycode
Copy link
Member

Bearer Authentication can be enabled in Swagger when applying a security property.

swagger.json

{
 "/identity-providers/{id}": {
   "delete": {
     "consumes": ...,
     "parameters": ...,
     "produces": ...,
     "responses": ...,
     "security": [
       {
         "bearer": []
       }
     ]
   }
 }
}

Until we figure out how to internally store the access token (this.accessToken), we can add a parameter to functions which map authenticated endpoints, so that users can supply a callback which is responsible for returning the access token.

Suggestion

async deleteById(id: string, accessTokenCallback: () => Promise<string>): Promise<void> {
  const accessToken = await accessTokenCallback();
  const config: AxiosRequestConfig = {
    headers: {
      Authorization: `Bearer ${decodeURIComponent(accessToken)}`
    },
    method: 'delete',
    url: `/identity-providers/${id}`,
    withCredentials: true,
  };

  await this.apiClient.request(config);
}
@arkraft
Copy link

arkraft commented Aug 7, 2019

Maybe the tokenCallback could be set as an option in the APIClient constructor. And every route which is configured with the bearer security setting would retrieve the token when needed. This way i would not need to add the function to each call in an API which depends on it for every route.

@ffflorian
Copy link
Member

ffflorian commented Aug 7, 2019

@arkraft Good point, but what about different authorizations for some endpoints? We should maybe also add the tokenCallback as an optional argument?

@ffflorian
Copy link
Member

ffflorian commented Aug 7, 2019

@arkraft what we are implementing here is the security declaration in the operation object. What you are talking about is the security declaration in the swagger object, right?

The difference is, that the security declaration in an operation object only apply to this specific operation, while the security declaration in the swagger object applies to the whole API.

@ffflorian ffflorian changed the title Add support for "Bearer Authentication" Add support for "Bearer Authentication" in operations Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants