<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                # Personal access tokens > 原文:[https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) * [Creating a personal access token](#creating-a-personal-access-token) * [Revoking a personal access token](#revoking-a-personal-access-token) * [Token activity](#token-activity) * [Limiting scopes of a personal access token](#limiting-scopes-of-a-personal-access-token) * [Programmatically creating a personal access token](#programmatically-creating-a-personal-access-token) * [Programmatically revoking a personal access token](#programmatically-revoking-a-personal-access-token) # Personal access tokens[](#personal-access-tokens "Permalink") 版本歷史 * 在 GitLab 8.8 中[引入](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/3749) . * 在 GitLab 12.6 中添加了[有關令牌過期的通知](https://gitlab.com/gitlab-org/gitlab/-/issues/3649) . * 在[GitLab Ultimate](https://about.gitlab.com/pricing/) 12.6 中添加了[令牌生存期限制](https://gitlab.com/gitlab-org/gitlab/-/issues/3649) . If you’re unable to use [OAuth2](../../api/oauth2.html), you can use a personal access token to authenticate with the [GitLab API](../../api/README.html#personalproject-access-tokens). 您還可以將個人訪問令牌與 Git 一起使用,以通過 HTTP 或 SSH 進行身份驗證. 啟用[兩因素身份驗證(2FA)](../account/two_factor_authentication.html)時,需要個人訪問令牌. 在這兩種情況下,都可以使用令牌代替密碼進行身份驗證. 個人訪問令牌在您定義的日期 UTC 午夜到期. * GitLab 每天在世界標準時間 01:00 AM 進行檢查,以識別將在 7 天內到期的個人訪問令牌. 這些令牌的所有者通過電子郵件通知. * 在 GitLab Ultimate 中,管理員可以[限制個人訪問令牌的壽命](../admin_area/settings/account_and_limit_settings.html#limiting-lifetime-of-personal-access-tokens-ultimate-only) . * 在 GitLab Ultimate 中,管理員可以[切換個人訪問令牌到期的執行](../admin_area/settings/account_and_limit_settings.html#optional-enforcement-of-personal-access-token-expiry-ultimate-only) . 有關如何使用個人訪問令牌向 API 進行身份驗證的示例,請參見[API 文檔中](../../api/README.html#personalproject-access-tokens)的以下部分. GitLab 還提供了[模擬令牌](../../api/README.html#impersonation-tokens) ,這些[令牌](../../api/README.html#impersonation-tokens)是管理員通過 API 創建的. 它們非常適合作為特定用戶的自動身份驗證. ## Creating a personal access token[](#creating-a-personal-access-token "Permalink") 您可以在 GitLab 個人資料中創建任意數量的個人訪問令牌. 1. 登錄到 GitLab. 2. 點擊右上角的頭像,然后選擇**設置** . 3. 在" **用戶設置"**菜單上,選擇" **訪問令牌"** . 4. 選擇令牌的名稱和可選的到期日期. 5. 選擇[所需的范圍](#limiting-scopes-of-a-personal-access-token) . 6. 單擊**創建個人訪問令牌**按鈕. 7. 將個人訪問令牌保存在安全的地方. 離開或刷新頁面后,將無法再次訪問它. ### Revoking a personal access token[](#revoking-a-personal-access-token "Permalink") 您可以隨時單擊" **活動個人訪問令牌"**區域下的相應" **撤消"**按鈕來撤消任何個人訪問令牌. ### Token activity[](#token-activity "Permalink") 您可以從" **個人訪問令牌"**頁面**查看**上次使用**令牌的時間** . 令牌使用情況的更新每 24 小時固定一次. 對[API 資源](../../api/api_resources.html)和[GraphQL API 的](../../api/graphql/index.html)請求將更新令牌的用法. ## Limiting scopes of a personal access token[](#limiting-scopes-of-a-personal-access-token "Permalink") 可以使用一個或多個范圍創建個人訪問令牌,這些范圍允許給定令牌可以執行各種操作. 下表描述了可用范圍. | Scope | 引入 | Description | | --- | --- | --- | | `read_user` | [GitLab 8.15](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5951) | 允許訪問`/users`下的只讀端點. 本質上,允許[用戶 API](../../api/users.html)中的任何`GET`請求. | | `api` | [GitLab 8.15](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/5951) | 授予對 API 的完全讀寫訪問權限,包括所有組和項目,容器注冊表和程序包注冊表. | | `read_api` | [GitLab 12.10](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/28944) | 授予對 API 的讀取權限,包括所有組和項目,容器注冊表和程序包注冊表. | | `read_registry` | [GitLab 9.3](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/11845) | 如果項目是私有的并且需要授權,則允許讀取(拉出) [容器注冊表](../packages/container_registry/index.html)圖像. | | `sudo` | [GitLab 10.2](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/14838) | 允許以系統中的任何用戶身份執行 API 操作(如果經過身份驗證的用戶是管理員). | | `read_repository` | [GitLab 10.7](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/17894) | 允許通過`git clone`對存儲庫進行只讀訪問(拉). | | `write_repository` | [GitLab 11.11](https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/26021) | 允許通過`git clone`對存儲庫進行讀寫訪問(拉,推). 啟用 2FA 時,通過 HTTP 訪問 Git 存儲庫是必需的. | ## Programmatically creating a personal access token[](#programmatically-creating-a-personal-access-token "Permalink") 您可以以編程方式創建預定的個人訪問令牌,以用于自動化或測試. 您將需要足夠的訪問權限才能為 GitLab 實例運行[Rails 控制臺會話](../../administration/troubleshooting/debug.html#starting-a-rails-console-session) . 要使用用戶名`automation-bot`創建屬于用戶的令牌,請在 Rails 控制臺( `sudo gitlab-rails console` )中運行以下`sudo gitlab-rails console` : ``` user = User.find_by_username('automation-bot') token = user.personal_access_tokens.create(scopes: [:read_user, :read_repository], name: 'Automation token') token.set_token('token-string-here123') token.save! ``` 使用[GitLab Rails Runner](../../administration/troubleshooting/debug.html#using-the-rails-runner)可以將其簡化為單行 shell 命令: ``` sudo gitlab-rails runner "token = User.find_by_username('automation-bot').personal_access_tokens.create(scopes: [:read_user, :read_repository], name: 'Automation token'); token.set_token('token-string-here123'); token.save!" ``` **注意:**令牌字符串的長度必須為 20 個字符,否則將不會被識別為個人訪問令牌. 有效范圍的列表及其作用可以[在源代碼中](https://gitlab.com/gitlab-org/gitlab/-/blob/master/lib/gitlab/auth.rb)找到. ## Programmatically revoking a personal access token[](#programmatically-revoking-a-personal-access-token "Permalink") 您可以通過編程方式撤消個人訪問令牌. 您將需要足夠的訪問權限才能為 GitLab 實例運行[Rails 控制臺會話](../../administration/troubleshooting/debug.html#starting-a-rails-console-session) . 要撤銷已知令牌`token-string-here123` ,請在 Rails 控制臺( `sudo gitlab-rails console` )中運行以下`sudo gitlab-rails console` : ``` token = PersonalAccessToken.find_by_token('token-string-here123') token.revoke! ``` 可以使用[GitLab Rails Runner](../../administration/troubleshooting/debug.html#using-the-rails-runner)將其[簡化](../../administration/troubleshooting/debug.html#using-the-rails-runner)為單行 shell 命令: ``` sudo gitlab-rails runner "PersonalAccessToken.find_by_token('token-string-here123').revoke!" ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看