![PyPI Now Supports iOS and Android Wheels for Mobile Python Development](https://cdn.sanity.io/images/cgdhsj6q/production/96416c872705517a6a65ad9646ce3e7caef623a0-1024x1024.webp?w=400&fit=max&auto=format)
Security News
PyPI Now Supports iOS and Android Wheels for Mobile Python Development
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
github.com/bnixon67/msgraph4go
msgraph4go provides a Go interface for the Microsoft Graph API.
This is still a work in progress, but does have some working examples for OneDrive and OneNote
In order to use this package, you must Register an application with the Microsoft identity platform
Sign in to the Azure portal using either a work or school account or a personal Microsoft account.
If your account gives you access to more than one tenant, select your account in the top right corner, and set your portal session to the Azure AD tenant that you want.
Select the Azure Active Directory service, and then select App registrations > New registration.
When the Register an application page appears, enter your application's registration information:
https://login.microsoftonline.com/common/oauth2/nativeclient
In order to run the examples, you need to set the MSCLIENTID environmental variable to the Application (client) ID provided.
The current approach assumes the client runs on a host without a browser. The user is instructed to vist a URL to login and authorize the client. Once the login is successful, the user must copy the response URL and provide to the client program.
The token is requested for offline access, which should include a refresh token to allow access for a long period of time. The token is saved in the file provided to msgraph4go.New(...)
.
For example, on the first run without a token file:
~/go/src/github.com/bnixon67/msgraph4go/examples$ go run GetMyProfile.go
Vist the following URL in a browser to authenticate this application
After authentication, copy the response URL from the browser
https://login.microsoftonline.com/common/oauth2/v2.0/authorize?access_type=offline&client_id={client_id}&redirect_uri=https%3A%2F%2Flogin.microsoftonline.com%2Fcommon%2Foauth2%2Fnativeclient&response_type=code&scope=User.Read&state={state}
Copy and paste the URL into a browser with javascript enabled to login to your Microsoft account. Once logged in, then copy the URL from the browser into the program:
Enter the response URL:
https://login.microsoftonline.com/common/oauth2/nativeclient?code={code}&state={state}
{
"displayName": "First Last",
"givenName": "First",
"id": "{id}",
"surname": "Last",
"userPrincipalName": "{...}"
}
On subsequent runs (with a saved token file), the execution should be seamless.
You need to delete the token file is you use a different client ID or request scopes not already authorized for the current token.
A simple example, which returns a JSON result:
// Get Microsoft Application (client) ID
// The ID is not in the source code to avoid someone reusing the ID
clientID, present := os.LookupEnv("MSCLIENTID")
if !present {
log.Fatal("Must set MSCLIENTID")
}
msGraphClient := msgraph4go.New(".token.json", clientID, []string{"User.Read"})
resp, err := msGraphClient.Get("/me", nil)
if err != nil {
log.Fatal(err)
}
Another example that returns a custom User type:
// Get Microsoft Application (client) ID
// The ID is not in the source code to avoid someone reusing the ID
clientID, present := os.LookupEnv("MSCLIENTID")
if !present {
log.Fatal("Must set MSCLIENTID")
}
msGraphClient := msgraph4go.New(".token.json", clientID, []string{"User.Read"})
user, err := msGraphClient.GetMyProfile(nil)
if err != nil {
log.Fatal(err)
}
fmt.Println(msgraph4go.VarToJsonString(user))
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.