Skip to content

Thêm OneDrive Channel

Cần chuẩn bị trước

Yêu cầuVì sao cần
Microsoft accountDùng để access Microsoft admin pages và authorize OneDrive
ImgHost domain của bạnDùng cho OAuth callback URL
App registrationDùng để generate Client IDClient Secret
OneDrive accountDùng làm nơi lưu file thực tế

Các bước thiết lập

Bước 1: Mở Microsoft Entra ID

  1. Mở portal.azure.com.
  2. Tìm Microsoft Entra ID ở phía trên.
  3. Nếu trang cần tìm không hiện trong dropdown, chọn:
text
Continue searching in Microsoft Entra ID
  1. Mở Microsoft Entra ID.
  2. Mở App registrations.
  3. Nhấn New registration.

Bước 2: Register App

Trên trang New registration, điền:

TrườngNhập gì
NameTên dễ nhận biết, ví dụ imgbed-onedrive
Supported account typesChọn theo bảng bên dưới
Redirect URI typeWeb
Redirect URIhttps://your-domain.com/api/oauth/onedrive/callback

Gợi ý chọn account type:

Tình huống của bạnSupported Account Types
Chỉ dùng personal OneDriveChọn option cho personal Microsoft account.
Dùng cả personal và work/school accountsChọn option hỗ trợ cả personal và organizational accounts.
Chỉ dùng company hoặc school OneDriveChọn organizational account option.

Điền xong thì nhấn register.

Tạo OneDrive app

Bước 3: Sao chép App Information

Sau khi app được tạo, sao chép các giá trị này từ overview page:

Trường MicrosoftTrường ImgHost
Application (client) IDClient ID
Directory (tenant) IDTenant ID cho organizational accounts

Application and tenant IDs

Bước 4: Tạo Client Secret

  1. Mở Certificates & secrets.
  2. Nhấn New client secret.
  3. Nhập mô tả tùy ý.
  4. Chọn expiration period.
  5. Sao chép Value ngay sau khi tạo.

Lưu giá trị client secret

Bước 5: Thêm API Quyềns

  1. Mở API permissions.
  2. Nhấn Add a permission.
  3. Chọn Microsoft Graph.
  4. Chọn Delegated permissions.
  5. Thêm các permissions này:
QuyềnMục đích
Files.ReadWrite.AllUpload files, tạo folders và xóa files
offline_accessCho phép ImgHost lấy Refresh Token
User.ReadĐọc account và quota information

Bước 6: Điền OneDrive Channel

Trong Cài đặt tải lên, chọn OneDrive và điền:

Trường ImgHostNhập gì
Channel nameTên dễ nhận biết, ví dụ Main OneDrive
Client IDMicrosoft Application (client) ID
Client SecretClient Secret Value đã sao chép
Tenant IDDùng bảng bên dưới
Refresh TokenTạm thời để trống
Root directoryKhông bắt buộc. Mặc định là imgbed.
KhôngteKhông bắt buộc

Điền config kênh OneDrive

Cách điền Tenant ID:

Account Type You ChoseImgHost Tenant ID
Personal accountsconsumers
Personal + organizational accountscommon
Chỉ tổ chức hiện tạiDirectory (tenant) ID

Bước 7: Lấy Refresh Token

  1. Trong ImgHost, nhấn Get Token.
  2. Sign in vào Microsoft account bạn muốn kết nối.
  3. Phê duyệt authorization prompt.
  4. Callback page sẽ hiển thị Refresh Token.
  5. Sao chép token đó.
  6. Quay lại ImgHost và dán vào trường Refresh Token.

Sao chép refresh token

Bước 8: Save Channel

Sau khi điền đủ trường, save channel.

Luồng nhanh

text
Open portal.azure.com
-> Search for Microsoft Entra ID
-> Open App registrations
-> Register a new app
-> Fill Name / Supported account types / Web redirect URI
-> Register
-> Copy Application (client) ID
-> Check the callback URL in Authentication
-> Create a Client Secret in Certificates & secrets
-> Add permissions in API permissions
-> Fill Client ID / Client Secret / Tenant ID into ImgHost
-> Click Get Token
-> Copy the Refresh Token from the callback page
-> Paste it back into ImgHost and save

Tài liệu tham khảo

  1. Microsoft Entra app registration: https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app
  2. Microsoft identity platform authorization code flow: https://learn.microsoft.com/en-us/entra/identity-platform/v2-oauth2-auth-code-flow
  3. Microsoft Graph user authentication: https://learn.microsoft.com/en-us/graph/auth-v2-user

Released as user documentation for ImgHost.