Comments (6)
@manicminer I will look into this issue. Feel free to assign it to me.
from hamilton.
Good day, upon looking at the PR #39 i noticed the addition of (List/Remove/Assign)AppRoleAssignments in service principal which is awesome. Upon reading the graph documentation I noticed the Microsoft suggests best practice for app role assignments is to use AppRoleAssignedTo. Is there a plan to add these 3 endpoints?
Using the existing code i extended the serviceprincipal struct for my current solution to add those 3 functionalities but I do not want to step on anyone's toes, here is what i user if it helps as a starting point:
// ListAppRoleAsssignedTo retrieves a list of appRoleAssignment that users, groups,
// or client service principals have been granted for the given resource service principal.
func (c *ServicePrincipalsClient) ListAppRoleAsssignedTo(ctx context.Context, id string) (*[]AppRoleAssignment, int, error) {
resp, status, _, err := c.BaseClient.Get(ctx, GetHttpRequestInput{
ValidStatusCodes: []int{http.StatusOK},
Uri: Uri{
Entity: fmt.Sprintf("/servicePrincipals/%s/appRoleAssignedTo", id),
Params: url.Values{"$select": []string{"id"}},
HasTenantId: true,
},
})
if err != nil {
return nil, status, fmt.Errorf("ServicePrincipalsClient.BaseClient.Get(): %v", err)
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err)
}
var data struct {
AppRoleAssignments []AppRoleAssignment `json:"value"`
}
if err := json.Unmarshal(respBody, &data); err != nil {
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err)
}
return &data.AppRoleAssignments, status, nil
}
// AddAppRoleAssignedTo assigns an app role for a resource service principal, to a user, group, or client service principal.
func (c *ServicePrincipalsClient) AddAppRoleAssignedTo(ctx context.Context, servicePrincipalID, principalID, resourceID, appRoleID string) (*AppRoleAssignment, int, error) {
var status int
data := struct {
PrincipalID string `json:"principalID"`
ResourceID string `json:"resourceID"`
AppRoleID string `json:"appRoleID"`
}{
PrincipalID: principalID,
ResourceID: resourceID,
AppRoleID: appRoleID,
}
body, err := json.Marshal(data)
if err != nil {
return nil, status, fmt.Errorf("json.Marshal(): %v", err)
}
resp, status, _, err := c.BaseClient.Post(ctx, PostHttpRequestInput{
Body: body,
ValidStatusCodes: []int{http.StatusCreated},
Uri: Uri{
Entity: fmt.Sprintf("/servicePrincipals/%s/appRoleAssignedTo", servicePrincipalID),
HasTenantId: true,
},
})
if err != nil {
return nil, status, fmt.Errorf("ServicePrincipalsClient.BaseClient.Post(): %v", err)
}
defer resp.Body.Close()
respBody, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, status, fmt.Errorf("ioutil.ReadAll(): %v", err)
}
var appRoleAssignment AppRoleAssignment
if err := json.Unmarshal(respBody, &appRoleAssignment); err != nil {
return nil, status, fmt.Errorf("json.Unmarshal(): %v", err)
}
return &appRoleAssignment, status, nil
}
// DeleteAppRoleAssignedTo deletes an appRoleAssignment that a user, group, or client service principal has been granted for a resource service principal.
func (c *ServicePrincipalsClient) DeleteAppRoleAssignedTo(ctx context.Context, servicePrincipalID, appRoleAssignmentID string) (int, error) {
_, status, _, err := c.BaseClient.Delete(ctx, DeleteHttpRequestInput{
ValidStatusCodes: []int{http.StatusNoContent},
Uri: Uri{
Entity: fmt.Sprintf("/servicePrincipals/%s/appRoleAssignedTo/%s", servicePrincipalID, appRoleAssignmentID),
HasTenantId: true,
},
})
if err != nil {
return status, fmt.Errorf("ServicePrincipalsClient.BaseClient.Delete(): %v", err)
}
return status, nil
}
from hamilton.
Hi @zbergus,
thank you for your comment and contribution. You are right about using the appRoleAssignedTo method as best practice.
It is already part of the existing PR, listing the relevant functions here below:
- func (c *ServicePrincipalsClient) ListAppRoleAssignments(){}
- func (c *ServicePrincipalsClient) AssignAppRoleForResource(){}
- func (c *ServicePrincipalsClient) RemoveAppRoleAssignment(){}
from hamilton.
hi @michaljirman I apologize!
I should have taken a look a bit more at the endpoint being used, I assumed from the method names that the other endpoints for the service principal were being used /appRoleAssignments
Very glad to find out it is the /appRoleAssignedTo endpoint being used!
from hamilton.
no worries @zbergus!
Maybe just my choice of the method names is not clear enough.
from hamilton.
This was added in #39
from hamilton.
Related Issues (20)
- Consider using beta version of API for accessPackage HOT 1
- azcli auth doesn't support MSAL scopes HOT 1
- Support for Continuous Access Evaluation (CAE) in conditional access session
- Support for Chat Resource HOT 2
- Group writebackConfiguration HOT 2
- Add the app ID for Azure Database for PostgreSQL - Flexible Server.
- Is it possible to fetch synchronizationSchema?
- ProvisionOnDemand() in SynchronizationJobClient returns error even though provisioning was successful
- AdministrativeUnits client uses wrong endpoint
- Replace double forward slash with single forward slash in all requests HOT 1
- How to manage enterprise application service principal saml claims? HOT 4
- Add support for synchronization GetSchema
- Add ServiceManagementReference to model
- Add support for ClientApplications in ConditionalAccessConditionSet
- DEBUG log entry showing up in production.
- Can "encoding/json" be replaced? HOT 1
- Add support for conditional access policy guestsOrExternalUsers settings
- [Question] Dynamic Distribution Lists and mailbox custom attributes HOT 1
- Error: no Authorizer could be configured, please check your configuration
- Help getting user emails
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hamilton.