| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
package adal |
| 19 |
|
| 20 |
import ( |
| 21 |
"context" |
| 22 |
"net/http" |
| 23 |
"time" |
| 24 |
) |
| 25 |
|
| 26 |
func getMSIEndpoint(ctx context.Context, sender Sender) (*http.Response, error) { |
| 27 |
tempCtx, cancel := context.WithTimeout(ctx, 2*time.Second) |
| 28 |
defer cancel() |
| 29 |
req, _ := http.NewRequest(http.MethodGet, msiEndpoint, nil) |
| 30 |
req = req.WithContext(tempCtx) |
| 31 |
q := req.URL.Query() |
| 32 |
q.Add("api-version", msiAPIVersion) |
| 33 |
req.URL.RawQuery = q.Encode() |
| 34 |
return sender.Do(req) |
| 35 |
} |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
func (mt *MultiTenantServicePrincipalToken) EnsureFreshWithContext(ctx context.Context) error { |
| 40 |
if err := mt.PrimaryToken.EnsureFreshWithContext(ctx); err != nil { |
| 41 |
return err |
| 42 |
} |
| 43 |
for _, aux := range mt.AuxiliaryTokens { |
| 44 |
if err := aux.EnsureFreshWithContext(ctx); err != nil { |
| 45 |
return err |
| 46 |
} |
| 47 |
} |
| 48 |
return nil |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
func (mt *MultiTenantServicePrincipalToken) RefreshWithContext(ctx context.Context) error { |
| 53 |
if err := mt.PrimaryToken.RefreshWithContext(ctx); err != nil { |
| 54 |
return err |
| 55 |
} |
| 56 |
for _, aux := range mt.AuxiliaryTokens { |
| 57 |
if err := aux.RefreshWithContext(ctx); err != nil { |
| 58 |
return err |
| 59 |
} |
| 60 |
} |
| 61 |
return nil |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
func (mt *MultiTenantServicePrincipalToken) RefreshExchangeWithContext(ctx context.Context, resource string) error { |
| 66 |
if err := mt.PrimaryToken.RefreshExchangeWithContext(ctx, resource); err != nil { |
| 67 |
return err |
| 68 |
} |
| 69 |
for _, aux := range mt.AuxiliaryTokens { |
| 70 |
if err := aux.RefreshExchangeWithContext(ctx, resource); err != nil { |
| 71 |
return err |
| 72 |
} |
| 73 |
} |
| 74 |
return nil |
| 75 |
} |