ListOAuthApps lists the reviewed OAuth Applications for the specified organization (whether approved or denied).
(org string)
| 47 | // ListOAuthApps lists the reviewed OAuth Applications for the |
| 48 | // specified organization (whether approved or denied). |
| 49 | func (c *Client) ListOAuthApps(org string) ([]*OAuthApp, error) { |
| 50 | doc, err := c.get("/organizations/%v/settings/oauth_application_policy", org) |
| 51 | if err != nil { |
| 52 | return nil, err |
| 53 | } |
| 54 | |
| 55 | var apps []*OAuthApp |
| 56 | doc.Find(".oauth-application-allowlist ul > li").Each(func(_ int, s *goquery.Selection) { |
| 57 | var app OAuthApp |
| 58 | app.Name = s.Find(".request-info strong").First().Text() |
| 59 | app.Description = s.Find(".request-info .application-description").Text() |
| 60 | |
| 61 | if editURL, ok := s.Find(".request-indicator a.edit-link").Attr("href"); ok { |
| 62 | app.ID = intFromLastPathSegment(editURL) |
| 63 | } |
| 64 | |
| 65 | if r := s.Find(".request-indicator .requestor"); r.Length() > 0 { |
| 66 | app.State = OAuthAppRequested |
| 67 | app.RequestedBy = r.Text() |
| 68 | if editURL, ok := s.Find(".request-indicator a").Last().Attr("href"); ok { |
| 69 | app.ID = intFromLastPathSegment(editURL) |
| 70 | } |
| 71 | } else if r := s.Find(".request-indicator .approved-request"); r.Length() > 0 { |
| 72 | app.State = OAuthAppApproved |
| 73 | } else if r := s.Find(".request-indicator .denied-request"); r.Length() > 0 { |
| 74 | app.State = OAuthAppDenied |
| 75 | } |
| 76 | apps = append(apps, &app) |
| 77 | }) |
| 78 | |
| 79 | return apps, nil |
| 80 | } |
| 81 | |
| 82 | func intFromLastPathSegment(s string) int { |
| 83 | seg := strings.Split(s, "/") |