Reputation: 109
I'm trying to create a sharepoint webpart using the new sharepoint framework, which uses the microsoft graph as shown here:
Here is a sample that I am using for reference.
I created a new project using the yeoman generator for sharepoint.
Installed adal: npm install adal-angular
Installed typings for adal: typings install adal --source dt --global --save
Copied the relevant parts from the WebPart.tsx file:
const AuthenticationContext = require('adal-angular');
import adalConfig from '../AdalConfig';
import { IAdalConfig } from '../../IAdalConfig';
import '../../WebPartAuthenticationContext';
export default class ReactClient extends React.Component<IReactClientProps, IReactClientState> {
private authCtx: adal.AuthenticationContext;
constructor(props: IReactClientProps, state: IReactClientState) {
super(props);
}
this.state = {
loading: false,
error: null,
signedIn: false
};
const config: IAdalConfig = adalConfig;
config.popUp = true;
config.webPartId = this.props.webPartId;
config.callback = (error: any, token: string): void => {
this.setState((previousState: IReactClientState, currentProps: IReactClientProps): IReactClientState => {
previousState.error = error;
previousState.signedIn = !(!this.authCtx.getCachedUser());
return previousState;
});
};
this.authCtx = new AuthenticationContext(config);
AuthenticationContext.prototype._singletonInstance = undefined;
}
The line:
private authCtx: adal.AuthenticationContext;
has no problem identifying the namespace adal that is created in the adal type file.
However, the line:
this.authCtx = new AuthenticationContext(config);
gives me the error: Cannot use 'new' with an expression whose type lacks a call or construct signature
The constructor is there in the adal type file. I don't see what's missing. I'm hoping one of you guys can shed some light on it for me.
Thanks,
Upvotes: 3
Views: 7528
Reputation: 9798
Is AuthenticationContext
in scope? Looks like only adl.AuthenticationContext
is in scope.
this.authCtx = new adl.AuthenticationContext(config);
or
import { AuthenticationContext } from 'path/to/adl'
at the top of the file.
Upvotes: 1