ms-onepoint
v1.0.8
Published
It is of depenecie for upload files for onedrive and sharepoint
Downloads
11
Readme
ms-onepoint
Description
Project that integrates functions to interact with Microsoft Azure and OneDrive APIS.
Install
$ npm install ms-onepoint
Configurations of Credentials
Returns: Functions and Methods
| Functions | Type | Description |
|--------------------| ----------------- | ----------------------------------------------------------------------------------------------- |
| authOneDrive | - | Authentication with OneDrive using an authorization code.
| generateCode | - | Generation of authorization code
| refreshToken | - | Access token update.
| createSharedLink | - | Creating a shared link.
| uploadFileToOneDrive | - | Uploading files to OneDrive.
Examples
Require module
const onepoint = require("ms-onepoint")
- Configuration of services of ms-onepoint
onepoint.configureCredentials({
drive: {
driveId: '',
parentId: ''
},
microsoftAzure: {
clientId: '',
clientSecret: '',
redirectUri: '',
}
})
GenerateCode
Returns: This method is for generate code for auth and generate with code genereated
const GenerateAuthCode = async () => {
const codeAccess = await onepoint.generateAuthCode();
return codeAccess;
};
AuthOneDrive
Returns: This method is for generate refreshToken for genereated tokens
const AuthenticateCodeAccess = async () => {
const response = await onepoint.authOneDrive({
code: process.env.ONEDRIVE_CODE
};
return codeAccess;
};
RefreshAccessToken
Returns: This generate refreshToken for uploadFile
const RefreshAccessToken = async (req, res) => {
const { access_token } = await onepoint.refreshAccessToken({
refreshAccessToken: process.env.ONEDRIVE_REFRESH_TOKEN
});
return access_token;
};
UploadFileToOneDrive
Returns: This method is for upload file with refreshToken genereated
const UploadFileToOneDrive = async (req, res) => {
const uploadFile = await onepoint.uploadFileToOneDrive({
authToken: access_token,
data: fs.readFileSync('./exmaple.png'),
fileName: 'exmaple.png'
});
return uploadFile.id;
};
CreateSharedLink
Returns: The body of the request defines properties of the sharing link your application is requesting shareLink Docs
const CreateSharedLink = async (req, res) => {
const { link } = await onepoint.createSharedLink({
authToken: access_token,
fileId: id,
type: { type: 'edit' }
});
return link;
};