-
Notifications
You must be signed in to change notification settings - Fork 221
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
If the security scheme is provided, Kiota should use it to create the right auth object #5070
Comments
Trying to add a couple of precisions here.
Questions for you @maisarissi :
|
Thanks for adding more details to the issue. On top of the 4 items you mentioned, I would expect:
The scenario where you need to do more than one authenticationq. Kiota should add a validation for multiple auth in one operation and thrown an error if that's the case.
Just to make sure I understand what you mean by this is like, one created for example an oauth2 security scheme in components but in the operation they referencing a bearer one that was never added to the security scheme in the components? If that's the case, I believe OpenAPI spec says this is not valid and that the operation security entries should match the ones in the component security scheme. So we should validate and thrown an error.
For oauth, when one is creating the auth registration in the Teams Developer Portal, scopes needed to be included there. In the plugin manifest, there is no place for us to add that info, maybe we could thrown an warning or log to list all scopes? This might be helpful for one when creating the auth registration.
Yes. The intention here is for us to follow the same pattern as TTK. When using TTK to create the auth registration in ones behalf, TTK creates and env variable with that name that will then be replaced when provisioning. See https://github.com/OfficeDev/teams-toolkit/blob/7422a1dffb7d54ca5e926e025fcdc72ae0380e17/packages/spec-parser/src/manifestUpdater.ts#L122 |
Thank you for the additional information.
Can you start a conversation with them so we can define an additional field for us to drop the scope information in please? We'll also need to consider whether application only scenarios are a thing or not.
I'm going to ask the question again: do you want |
Actually I was thinking on us logging in Kiota somehow the scopes, so one could easy get a list of the scopes and add in their auth registration in TDP manually.
I think we should do programmatically; same way TTK does: if (pluginAuthObj.type !== "None") {
const safeRegistrationIdName = Utils.getSafeRegistrationIdEnvName(
`${authInfo.name}_${ConstantString.RegistrationIdPostfix[authInfo.authScheme.type]}`
);
pluginAuthObj.reference_id = `\${{${safeRegistrationIdName}}}`;
} static readonly RegistrationIdPostfix: { [key: string]: string } = {
apiKey: "REGISTRATION_ID",
oauth2: "CONFIGURATION_ID",
http: "REGISTRATION_ID",
openIdConnect: "REGISTRATION_ID",
}; |
Should we ignore the value of the document root's |
This is how I understand the spec
What do you think? |
If you're referring to the OpenAPI spec, I understood it differently. According to the spec, there are 2 locations for the security requirement object. The root of the document and under individual operations.
Security being defined at the operation level means the top-level security information is ignored for the operation level security information. |
@calebkiage As far as I could understand from the OpenAPI spec, one can only have security requirement object (operation level) if there is a security schema object (root - under components) with the same name. |
That is true @maisarissi, but the security requirement object can be specified in both the top level and the operation level. For example, the following is a valid OpenAPI document: openapi: 3.0.0
info:
title: test
version: "1.0"
security:
- jwt0: [] # should apply to all operations that don't have security defined
paths:
/test0:
get:
description: description for test0 path (uses jwt0 security)
responses:
'200':
description: test
/test1:
get:
description: description for test1 path (uses apiKey0 security
responses:
'200':
description: test
security:
- apiKey0: [] # overrides the root security
components:
securitySchemes:
apiKey0:
type: apiKey
name: x-api-key
in: header
jwt0:
type: http
scheme: bearer
bearerFormat: JWT My question is, what do we do about this situation? My suggestion is: |
I think @calebkiage got it right:
Special case here is even to remove any security requirement for the given operation (same link):
Meaning, we really need to consider first the operation level security requirements and look on the requirements at the root OpenAPI Object only if there is none defined on the operation level - meaning, no security object defined there. Additionally,
Note: included in the array, meaning in addition to other requirement objects (on the same level). Implication for us is that we need to decide how to go about it- one entry to generate won't do anymore without being able to mark it as optional. @maisarissi
(a) Several requirements
More complex example of an optional authentication by using either one of the API keys or OAuth2 authentication.
If we keep our rule to throw error on multiple requirements defined, we won't be able to support a such API. (b) Several schemes Example of an optional authentication of an API which supports a pair of query parameters to be included in requests:
We need to decide whether we want to support this option or not. @maisarissi , @darrelmiller ? |
@petrhollayms Thank you Petr for one of the more comprehensive explanations of OpenAPI security that I have seen. It is somewhat terrifying to think that, as complex as it is, the OpenAPI security model is not nearly sophisticated enough to represent many real world scenarios. But I digress. There are two questions that need to be answered:
One approach is to say, we only create manifests with features that Copilot supports. That comes with the risk of us having to constantly update our generation process as new feature support is rolled out. Another approach is to support all the features of the Plugin Manifest, and then use validation rules to indicate when someone is using a feature that is currently not supported by the implementation. As our goal is for the Plugin Manifest to be used by more than just M365 Copilot, I would recommend the latter approach. It is also much easier to remove a validation rule than it is to update the generation process. So, based on this, we need to look at the constraints of the Plugin Manifest first. The Plugin Manifest supports having multiple "Security Requirements" by using multiple runtimes that point to the same OpenAPI but using slightly different names for the functions. However, it does not currently support the notion of multiple Schemes per security Requirement. As multiple schemes per security Requirement are an "AND" scenario, it means we cannot support calling an API that has multiple schemes. (That sucks and should be fixed in our Copilot implementation because APIM solutions do this all the time). |
@calebkiage any objection to closing this issue as done? |
OpenAPI manifest can contain API security definitions using the security scheme and they can be referenced either globally or per operation.
If the security scheme is provided and the auth type is supported (vide #5071) Kiota should create the right auth object in the plugin manifest.
The object pattern is like the following:
Pattern A will be used for HTTP+Bearer Token, API Key and OpenId Connect:
Pattern B will be used for Oauth:
For the reference_id, we are using the same pattern as TTK. Vide https://github.com/OfficeDev/teams-toolkit/blob/7422a1dffb7d54ca5e926e025fcdc72ae0380e17/packages/spec-parser/src/manifestUpdater.ts#L122
Acceptance Criteria:
The text was updated successfully, but these errors were encountered: