Documentation ¶
Overview ¶
Package public provides a client for authentication of "public" applications. A "public" application is defined as an app that runs on client devices (android, ios, windows, linux, ...). These devices are "untrusted" and access resources via web APIs that must authenticate.
Index ¶
- type Account
- type AcquireTokenByAuthCodeOption
- type AcquireTokenByAuthCodeOptions
- type AcquireTokenSilentOption
- type AcquireTokenSilentOptions
- type AuthResult
- type Client
- func (pca Client) Accounts() []Account
- func (pca Client) AcquireTokenByAuthCode(ctx context.Context, code string, redirectURI string, scopes []string, ...) (AuthResult, error)
- func (pca Client) AcquireTokenByDeviceCode(ctx context.Context, scopes []string) (DeviceCode, error)
- func (pca Client) AcquireTokenByUsernamePassword(ctx context.Context, scopes []string, username string, password string) (AuthResult, error)
- func (pca Client) AcquireTokenInteractive(ctx context.Context, scopes []string, options ...InteractiveAuthOption) (AuthResult, error)
- func (pca Client) AcquireTokenSilent(ctx context.Context, scopes []string, options ...AcquireTokenSilentOption) (AuthResult, error)
- func (pca Client) CreateAuthCodeURL(ctx context.Context, clientID, redirectURI string, scopes []string) (string, error)
- type DeviceCode
- type DeviceCodeResult
- type InteractiveAuthOption
- type InteractiveAuthOptions
- type Option
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AcquireTokenByAuthCodeOption ¶
type AcquireTokenByAuthCodeOption func(a *AcquireTokenByAuthCodeOptions)
AcquireTokenByAuthCodeOption changes options inside AcquireTokenByAuthCodeOptions used in .AcquireTokenByAuthCode().
func WithChallenge ¶
func WithChallenge(challenge string) AcquireTokenByAuthCodeOption
WithChallenge allows you to provide a code for the .AcquireTokenByAuthCode() call.
type AcquireTokenByAuthCodeOptions ¶
type AcquireTokenByAuthCodeOptions struct {
Challenge string
}
AcquireTokenByAuthCodeOptions contains the optional parameters used to acquire an access token using the authorization code flow.
type AcquireTokenSilentOption ¶
type AcquireTokenSilentOption func(a *AcquireTokenSilentOptions)
AcquireTokenSilentOption changes options inside AcquireTokenSilentOptions used in .AcquireTokenSilent().
func WithSilentAccount ¶
func WithSilentAccount(account Account) AcquireTokenSilentOption
WithSilentAccount uses the passed account during an AcquireTokenSilent() call.
type AcquireTokenSilentOptions ¶
type AcquireTokenSilentOptions struct { // Account represents the account to use. To set, use the WithSilentAccount() option. Account Account }
AcquireTokenSilentOptions are all the optional settings to an AcquireTokenSilent() call. These are set by using various AcquireTokenSilentOption functions.
type AuthResult ¶
type AuthResult = base.AuthResult
AuthResult contains the results of one token acquisition operation. For details see https://aka.ms/msal-net-authenticationresult
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a representation of authentication client for public applications as defined in the package doc. For more information, visit https://docs.microsoft.com/azure/active-directory/develop/msal-client-applications.
func (Client) Accounts ¶
Accounts gets all the accounts in the token cache. If there are no accounts in the cache the returned slice is empty.
func (Client) AcquireTokenByAuthCode ¶
func (pca Client) AcquireTokenByAuthCode(ctx context.Context, code string, redirectURI string, scopes []string, options ...AcquireTokenByAuthCodeOption) (AuthResult, error)
AcquireTokenByAuthCode is a request to acquire a security token from the authority, using an authorization code. The specified redirect URI must be the same URI that was used when the authorization code was requested.
func (Client) AcquireTokenByDeviceCode ¶
func (pca Client) AcquireTokenByDeviceCode(ctx context.Context, scopes []string) (DeviceCode, error)
AcquireTokenByDeviceCode acquires a security token from the authority, by acquiring a device code and using that to acquire the token. Users need to create an AcquireTokenDeviceCodeParameters instance and pass it in.
func (Client) AcquireTokenByUsernamePassword ¶
func (pca Client) AcquireTokenByUsernamePassword(ctx context.Context, scopes []string, username string, password string) (AuthResult, error)
AcquireTokenByUsernamePassword acquires a security token from the authority, via Username/Password Authentication. NOTE: this flow is NOT recommended.
func (Client) AcquireTokenInteractive ¶
func (pca Client) AcquireTokenInteractive(ctx context.Context, scopes []string, options ...InteractiveAuthOption) (AuthResult, error)
AcquireTokenInteractive acquires a security token from the authority using the default web browser to select the account. https://docs.microsoft.com/en-us/azure/active-directory/develop/msal-authentication-flows#interactive-and-non-interactive-authentication
func (Client) AcquireTokenSilent ¶
func (pca Client) AcquireTokenSilent(ctx context.Context, scopes []string, options ...AcquireTokenSilentOption) (AuthResult, error)
AcquireTokenSilent acquires a token from either the cache or using a refresh token.
type DeviceCode ¶
type DeviceCode struct { // Result holds the information about the device code (such as the code). Result DeviceCodeResult // contains filtered or unexported fields }
DeviceCode provides the results of the device code flows first stage (containing the code) that must be entered on the second device and provides a method to retrieve the AuthenticationResult once that code has been entered and verified.
func (DeviceCode) AuthenticationResult ¶
func (d DeviceCode) AuthenticationResult(ctx context.Context) (AuthResult, error)
AuthenticationResult retreives the AuthenticationResult once the user enters the code on the second device. Until then it blocks until the .AcquireTokenByDeviceCode() context is cancelled or the token expires.
type DeviceCodeResult ¶
type DeviceCodeResult = accesstokens.DeviceCodeResult
type InteractiveAuthOption ¶
type InteractiveAuthOption func(*InteractiveAuthOptions)
InteractiveAuthOption changes options inside InteractiveAuthOptions used in .AcquireTokenInteractive().
func WithRedirectURI ¶
func WithRedirectURI(redirectURI string) InteractiveAuthOption
WithRedirectURI uses the specified redirect URI for interactive auth.
type InteractiveAuthOptions ¶
type InteractiveAuthOptions struct { // Used to specify a custom port for the local server. http://localhost:portnumber // All other URI components are ignored. RedirectURI string }
InteractiveAuthOptions contains the optional parameters used to acquire an access token for interactive auth code flow.
type Option ¶
type Option func(o *Options)
Option is an optional argument to the New constructor.
func WithAuthority ¶
WithAuthority allows for a custom authority to be set. This must be a valid https url.
func WithCache ¶
func WithCache(accessor cache.ExportReplace) Option
WithCache allows you to set some type of cache for storing authentication tokens.
func WithHTTPClient ¶
func WithHTTPClient(httpClient ops.HTTPClient) Option
WithHTTPClient allows for a custom HTTP client to be set.
type Options ¶
type Options struct { // Accessor controls cache persistence. By default there is no cache persistence. // This can be set with the WithCache() option. Accessor cache.ExportReplace // The host of the Azure Active Directory authority. The default is https://login.microsoftonline.com/common. // This can be changed with the WithAuthority() option. Authority string // The HTTP client used for making requests. // It defaults to a shared http.Client. HTTPClient ops.HTTPClient }
Options configures the Client's behavior.