Documentation
¶
Index ¶
Constants ¶
const APIVersion string = "v1.0"
APIVersion represents the APIVersion of msgraph used by this implementation
const BaseURL string = "https://graph.microsoft.com"
BaseURL represents the URL used to perform all ms graph API-calls
const LoginBaseURL string = "https://login.microsoftonline.com"
LoginBaseURL represents the basic url used to acquire a token for the msgraph api
const MaxPageSize int = 999
MaxPageSize is the maximum Page size for an API-call. This will be rewritten to use paging some day. Currently limits environments to 999 entries (e.g. Users, CalendarEvents etc.)
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct { sync.Mutex // lock it when performing an API-call to synchronize it TenantID string // See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-tenant-id ApplicationID string // See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key ClientSecret string // See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-create-service-principal-portal#get-application-id-and-authentication-key // contains filtered or unexported fields }
Client represents a msgraph API connection instance.
An instance can also be json-unmarshalled an will immediately be initialized, hence a Token will be grabbed. If grabbing a token fails the JSON-Unmarshal returns an error.
func NewGraphClient ¶
NewGraphClient creates a new Client instance with the given parameters and grab's a token.
Returns an error if the token can not be initialized. This method does not have to be used to create a new Client
func (*Client) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshal to be used by the json-library. This method additionally to loading the TenantID, ApplicationID and ClientSecret immediately gets a Token from msgraph (hence initialize this GraphAPI instance) and returns an error if any of the data provided is incorrect or the token can not be acquired
type Item ¶
type Item struct { CreatedAt time.Time `json:"createdDateTime"` ID string `json:"id"` LastMod time.Time `json:"lastModifiedDateTime"` Name string `json:"name"` WebURL string `json:"webUrl"` Size int64 `json:"size"` CreatedBy struct { User `json:"user"` } `json:"createdBy"` LastModifiedBy struct { User `json:"user"` } `json:"lastModifiedBy"` ParentReference Reference `json:"parentReference"` FileSystemInfo struct { CreatedDateTime time.Time `json:"createdDateTime"` LastModifiedDateTime time.Time `json:"lastModifiedDateTime"` } `json:"fileSystemInfo"` Folder *struct { ChildCount int `json:"childCount"` } `json:"folder,omitempty"` DownloadURL string `json:"@microsoft.graph.downloadUrl,omitempty"` File *struct { MimeType string `json:"mimeType"` } `json:"file,omitempty"` Image *struct { Height int `json:"height"` Width int `json:"width"` } `json:"image,omitempty"` }
type ReqError ¶
type ReqError struct { URL string `json:"-"` StatusCode int `json:"-"` Err struct { Code string `json:"code"` Message string `json:"message"` InnerError struct { Date string `json:"date"` RequestID string `json:"request-id"` ClientRequestID string `json:"client-request-id"` } `json:"innerError"` } `json:"error"` Raw string `json:"-"` // contains filtered or unexported fields }
type Token ¶
type Token struct { TokenType string // should always be "Bearer" for msgraph API-calls NotBefore time.Time // time when the access token starts to be valid ExpiresOn time.Time // time when the access token expires Resource string // will most likely always be https://graph.microsoft.com, hence the BaseURL AccessToken string // the access-token itself }
func (Token) GetAccessToken ¶
GetAccessToken teturns the API access token in Bearer format representation ready to send to the API interface.
func (Token) HasExpired ¶
HasExpired returns true if the token has already expired.
Hint: this is a wrapper for >>!token.IsStillValid()<<
func (Token) IsAlreadyValid ¶
IsAlreadyValid returns true if the token is already valid, hence the NotBefore is before the current time. Otherwise false.
Hint: The current time is determined by time.Now()
func (Token) IsStillValid ¶
IsStillValid returns true if the token is still valid, hence the current time is before ExpiresOn. Does NOT check it the token is yet valid or in the future.
Hint: The current time is determined by time.Now()
func (Token) IsValid ¶
IsValid returns true if the token is already valid and is still valid. Otherwise false.
Hint: this is a wrapper for >>token.IsAlreadyValid() && token.IsStillValid()<<
func (*Token) UnmarshalJSON ¶
UnmarshalJSON implements the json unmarshal to be used by the json-library.
Hint: the UnmarshalJSON also checks immediately if the token is valid, hence the current time.Now() is after NotBefore and before ExpiresOn
func (Token) WantsToBeRefreshed ¶
WantsToBeRefreshed returns true if the token is already invalid or close to expire (10 second before ExpiresOn), otherwise false. time.Now() is used to determine the current time.