Skip to content

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. The library also supports Azure AD B2C.

License

Notifications You must be signed in to change notification settings

malleum-inc/microsoft-authentication-library-for-go

 
 

Repository files navigation

Microsoft Authentication Library (MSAL) for Go

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

Build Status

Go

Installation

Setting up Go

To install Go, visit this link.

Installing MSAL Go

go get -u github.com/AzureAD/microsoft-authentication-library-for-go/

Usage

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:

  1. MSAL separates public and confidential client applications. So, you would create an instance of a PublicClientApplication and ConfidentialClientApplication 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")
  1. 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)
  1. 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.

Roadmap

This is a preview library. Details of the roadmap will come soon in the wiki pages, along with release notes.

Community Help and Support

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.

Contributing

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.

Security Library

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.

Security Reporting

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");

About

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. The library also supports Azure AD B2C.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%