MSAL Go is a new addition to the MSAL family of libraries, not yet in public preview, that has been made available to gauge customer interest and to gather early feedback from the community. We welcome all contributors (see CONTRIBUTING.md) to help us grow our list of supported MSAL SDKs.
The MSAL library for Go is part of the Microsoft identity platform for developers (formerly named Azure AD) v2.0. It enables you to acquire security tokens to call protected APIs. It uses industry standard OAuth2 and OpenID Connect.
Quick links:
Getting Started | GoDoc | Wiki | Samples | Support |
---|
To install Go, visit this link.
go get -u github.com/AzureAD/microsoft-authentication-library-for-go/
Before using MSAL Go, you will need to register your application with the Microsoft identity platform.
Acquiring tokens with MSAL Go follows this general three step pattern. There might be some slight differences for other token acquisition flows. Here is a basic example:
- MSAL separates public and confidential client applications. So, you would create an instance of a
PublicClientApplication
andConfidentialClientApplication
and use this throughout the lifetime of your application.
publicClientApp, err := msal.CreatePublicClientApplication("your_client_id",
"https://login.microsoftonline.com/Enter_the_Tenant_Name_Here")
- MSAL comes packaged with an in-memory cache. Utilizing the cache is optional, but we would highly recommend it.
accounts := publicClientApp.GetAccounts()
// Assuming the user wanted the first account
userAccount := accounts[0]
scopes := []string{"your_scope"}
silentParams := msal.CreateAcquireTokenSilentParametersWithAccount(scopes, userAccount)
result, err := publicClientApp.AcquireTokenSilent(silentParams)
- If there is no suitable token in the cache, or you choose to skip this step, now we can send a request to AAD to obtain a token.
if err != nil {
// Based on the flow, you create the type of parameters
tokenParams := msal.CreateAcquireTokenxxxParameters(scopes, ...)
result, err := publicClientApp.AcquireTokenByxxx(tokenParams)
if err != nil {
log.Fatal(err)
}
}
accessToken := result.GetAccessToken()
You can view the dev apps on how to use MSAL Go with various application types in various scenarios. For more detailed information, please refer to the wiki.
This is a preview library. Details of the roadmap will come soon in the wiki pages, along with release notes.
We use Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browse existing issues to see if someone has had your question before. Please use the "msal" tag when asking your questions.
If you find and bug or have a feature request, please raise the issue on GitHub Issues.
This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
When you submit a pull request, a CLA bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repos using our CLA.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.
This library controls how users sign-in and access services. We recommend you always take the latest version of our library in your app when possible. We use semantic versioning so you can control the risk associated with updating your app. As an example, always downloading the latest minor version number (e.g. x.y.x) ensures you get the latest security and feature enhancements but our API surface remains the same. You can always see the latest version and release notes under the Releases tab of GitHub.
If you find a security issue with our libraries or services please report it to [email protected] with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts.
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License (the "License");