Code Monkey home page Code Monkey logo

ms-graph-cli's Introduction

demo

ms-graph-cli: tiny & elegant cli to authenticate microsoft graph

Description

ms-graph-cli helps you run through microsoft's get access on behalf of a user easily! Created mainly for helping onedrive & sharepoint get the access-token and refresh-token to access ms-graph API.

Graph permissons needed

  • onedrive: Files.Read.All Files.ReadWrite.All offline_access
  • sharepoint: Sites.Read.All Sites.ReadWrite.All offline_access

CLI usage

!Note: To automate the redirection process, ms-graph-cli needs your app's redirect_uri set to http://localhost:3000, the port can be changed as long as you have system permission to create a http server on that port

If you are somehow unable to meet the requirements of redirect_uri, please use the legacy version

# Print generated credentials to stdout
npx @beetcb/ms-graph-cli

# Save generated credentials to .env file
npx @beetcb/ms-graph-cli -s

# Specify the display language, support CN \ EN, default is EN
npx @beetcb/ms-graph-cli -l cn

# Or specify them both
npx @beetcb/ms-graph-cli -s -l cn

Generated credentials

It's a object(maybe .env-fromatted) contains following key-value pairs:

  • access_token: use it to access ms-graph
  • refresh_token: use it to refresh the access_token
  • redirect_uri: your application redirect uri
  • client_id: your application client id
  • client_secret: your application client secret(this can be ignored when using public client)
  • auth_endpoint: api endpoint to request token
  • drive_api: api endpoint to access your drive resource
  • graph_api: api endpoint to access ms-graph
  • site_id?: sharepoint site id

All fields in the object are your private information, please keep it safe.

TODO

  • Create a local server to catch the redirect code
  • Better error handling

ms-graph-cli's People

Contributors

arvinzjc avatar beetcb avatar spencerwooo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ms-graph-cli's Issues

Deploy type and graph permissions do not match in V0.3

This issue regards the deploy type selection and its corresponding permission sets observed in V0.3.

Env

Windows 10 (The same issue might be encountered in other platforms since I reckon it is not an OS-specific issue.)

Example output

√ Please select your OneDrive or SharePoint account type: » Global
√ Please select your deploy type (OneDrive or SharePoint): » OneDrive
√ Enter your client_id: ... test
√ Enter your client_secret: ... ****
√ Enter your redirect_uri ([Default] http://localhost:3000): ... http://localhost:3000

>>> https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=test&scope=Sites.Read.All+Sites.ReadWrite.All+offline_access...

Possible reasons

The hints/steps on the console have been defined in a JSON file hints.json. However, the new logic of categorising the deploy type seems incorrect. FYI, the value of res returned from getPromptWithHints(), as per the above example output, is as follows.

{
  account_type: 0,
  deploy_type: 0, // OneDrive, but in URL, permissions for SharePoint which would lead to incorrect scope.
  client_id: 'test',
  client_secret: 'test',
  redirect_uri: 'http://localhost:3000'
}

Suggested fix

pls see the pull request #6 .

Svg animation lagging

It just blocked the whole GitHub page

Consider re-recording it or transfrom it to .gif

Question about redirected url and authorization code

I cant make my refresh_token

D:\Microsoft_Graph_Security_API\QuickStarts\Node\onedrive-cf-index-main>npx @beetcb/ms-graph-cli
npx: installed 36 in 7.777s
? Please select your OneDrive or SharePoint account type: Global
? Please select your deploy type (OneDrive or SharePoint): OneDrive
? Enter your client_id: 1b973335-5c01-4a1f-9002-e4125725854b
? Enter your client_secret: -aHB.9kclrsDK-_p1252c3prxu1XxomI
? Enter your redirect_uri ([Default] http://localhost):
? Use your browser to visit this URL for login and authorization:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?client_id=1b973335-5c01-4a1f-9002-e4125725854b&scope=File
s.Read.All+Files.ReadWrite.All+offline_access&response_type=code&redirect_uri=http://localhost
Then enter the address you were redirected to(it's in your address bar):
https://a.a
Get token failed!Bad Request
{
client_id: '1b973335-5c01-4a1f-9002-e4125725854b',
client_secret: '-aHB.9kclrsDK-_p1252c3prxu1XxomI',
redirect_uri: 'http://localhost',
auth_endpoint: 'https://login.microsoftonline.com/common/oauth2/v2.0',
drive_api: 'https://graph.microsoft.com/v1.0/me/drive',
graph_api: 'https://graph.microsoft.com/v1.0'
}

Get token failed! Unauthorized

Hello,
I have tried using the app quite a few times and it always returns "Get token failed! Unauthorized" to me.
I have already given all of the permission to the app.

Please tell me what is wrong
Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.