Customization of auth providers and plugging in Kiota authproviders into Graph SDK
See original GitHub issueAuthentication Abstractions in Kiota:
interface AuthenticationProvider {
authenticateRequest:void;
}
abstract class BaseBearerTokenAuthenticationProvider {
public authenticateRequest{
//
}
abstract public getAuthorizationToken();
}
class AzureIdentityAuthenticationProvider extends BaseBearerTokenAuthenticationProvider{
public getAuthorizationToken(){
// return the access token;
}
}
Authentication Abstractions in current Graph JS SDK:
class AuthenticationHandler {
authProvider: AuthProvider
middleware.execute() or authenticateRequest(){
if(Graph Specific Condition){
const token = authProvider.getAccessToken();
appendToHeader("Authorization", token);
}
else {
deleteAuthHeader();
}
}
}
class AuthProvider
{
getAccessToken();
}
Currently the Graph JS SDK uses a composition pattern. The AuthenticationHandler which is a part of the middleware verifies
if the request url is a Graph URL or a custom host passed by the user and appends the authorization headers.
Goal :
Reuse Kiota AuthProviders such as the AzureIdentityAuthenticationProvider class and authentication abstractions as is in Graph SDKs.
Limitations:
Adding the customizations:
The authenticateRequest in BaseBearerTokenAuthenticationProvidershould append the authorization headers based on the custom conditions. Thereby, the custom logic should also get extended into the child classes such as the AzureIdentityAuthenticationProvider. This limits reusing the existing BaseBearerTokenAuthenticationProvider and the auth providers as is.
Solution:
-
Apply composition pattern in Kiota. Maintain separate classes, one with the
authenticateRequestand one with thegetAccesstoken. I suggest this as it promotes reuse of Kiota authorizaton abstractions and classes. -
Mantain separate
GraphBaseBearerTokenAuthenticationProviderandGraph AuthProviderswhich extends the former class.
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (12 by maintainers)
Top Related StackOverflow Question
Encapsulation over inheritance, I like the suggestion š
So effectively weād have
In terms of consumption the user would only have to do:
And the client could use the authentication provider as is for the fluent API or the access token provider for the existing arbitrary API. (by accessing the
accessTokenProviderproperty on theBaseBearerTokenAuthenticationProvider)Now, this adds a level of complexity but adds the advantage of making the providers reusable for both Kiota and the current JS SDK, (as well as other surfaces like MGT etcā¦)
@nikithauc did I capture properly what you were expressing? @andrueastman do you think we should apply that for all languages? Iām tempted to say yes for uniformity even if it means a bit more work. @sebastienlevert for the experience side of things and the impact on MGT.
@sebastienlevert This is something keep in mind and discuss about when considering the same version numbers for the packages.