This class is used for identifying and authorizing users for Github Apps. The reference can be found at https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps
| 46 | |
| 47 | |
| 48 | class ApplicationOAuth(NonCompletableGithubObject): |
| 49 | """ |
| 50 | This class is used for identifying and authorizing users for Github Apps. |
| 51 | |
| 52 | The reference can be found at |
| 53 | https://docs.github.com/en/developers/apps/building-github-apps/identifying-and-authorizing-users-for-github-apps |
| 54 | |
| 55 | """ |
| 56 | |
| 57 | def __init__( |
| 58 | self, |
| 59 | requester: Requester, |
| 60 | headers: dict[str, Any], |
| 61 | attributes: Any, |
| 62 | ) -> None: |
| 63 | # this object requires a request without authentication |
| 64 | requester = requester.withAuth(auth=None) |
| 65 | super().__init__(requester, headers, attributes) |
| 66 | |
| 67 | def _initAttributes(self) -> None: |
| 68 | self._client_id: Attribute[str] = NotSet |
| 69 | self._client_secret: Attribute[str] = NotSet |
| 70 | |
| 71 | def __repr__(self) -> str: |
| 72 | return self.get__repr__({"client_id": self._client_id.value}) |
| 73 | |
| 74 | @property |
| 75 | def client_id(self) -> str: |
| 76 | return self._client_id.value |
| 77 | |
| 78 | @property |
| 79 | def client_secret(self) -> str: |
| 80 | return self._client_secret.value |
| 81 | |
| 82 | def get_oauth_url(self, path: str) -> str: |
| 83 | if not path.startswith("/"): |
| 84 | path = f"/{path}" |
| 85 | |
| 86 | if self._requester.base_url == DEFAULT_BASE_URL: |
| 87 | base_url = DEFAULT_OAUTH_URL |
| 88 | else: |
| 89 | base_url = f"{self._requester.scheme}://{self._requester.hostname_and_port}/login/oauth" |
| 90 | return f"{base_url}{path}" |
| 91 | |
| 92 | def get_login_url( |
| 93 | self, |
| 94 | redirect_uri: str | None = None, |
| 95 | state: str | None = None, |
| 96 | login: str | None = None, |
| 97 | ) -> str: |
| 98 | """ |
| 99 | Return the URL you need to redirect a user to in order to authorize your App. |
| 100 | """ |
| 101 | parameters = {"client_id": self.client_id} |
| 102 | if redirect_uri is not None: |
| 103 | assert isinstance(redirect_uri, str), redirect_uri |
| 104 | parameters["redirect_uri"] = redirect_uri |
| 105 | if state is not None: |
no outgoing calls
no test coverage detected
searching dependent graphs…