ops.go

 1// Copyright (c) Microsoft Corporation.
 2// Licensed under the MIT license.
 3
 4/*
 5Package ops provides operations to various backend services using REST clients.
 6
 7The REST type provides several clients that can be used to communicate to backends.
 8Usage is simple:
 9
10	rest := ops.New()
11
12	// Creates an authority client and calls the UserRealm() method.
13	userRealm, err := rest.Authority().UserRealm(ctx, authParameters)
14	if err != nil {
15		// Do something
16	}
17*/
18package ops
19
20import (
21	"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/accesstokens"
22	"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/authority"
23	"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/internal/comm"
24	"github.com/AzureAD/microsoft-authentication-library-for-go/apps/internal/oauth/ops/wstrust"
25)
26
27// HTTPClient represents an HTTP client.
28// It's usually an *http.Client from the standard library.
29type HTTPClient = comm.HTTPClient
30
31// REST provides REST clients for communicating with various backends used by MSAL.
32type REST struct {
33	client *comm.Client
34}
35
36// New is the constructor for REST.
37func New(httpClient HTTPClient) *REST {
38	return &REST{client: comm.New(httpClient)}
39}
40
41// Authority returns a client for querying information about various authorities.
42func (r *REST) Authority() authority.Client {
43	return authority.Client{Comm: r.client}
44}
45
46// AccessTokens returns a client that can be used to get various access tokens for
47// authorization purposes.
48func (r *REST) AccessTokens() accesstokens.Client {
49	return accesstokens.Client{Comm: r.client}
50}
51
52// WSTrust provides access to various metadata in a WSTrust service. This data can
53// be used to gain tokens based on SAML data using the client provided by AccessTokens().
54func (r *REST) WSTrust() wstrust.Client {
55	return wstrust.Client{Comm: r.client}
56}