|
| 1 | +//----------------------------------------------------------------------------- |
| 2 | +// <copyright file="DropboxAppClient.cs" company="Dropbox Inc"> |
| 3 | +// Copyright (c) Dropbox Inc. All rights reserved. |
| 4 | +// </copyright> |
| 5 | +//----------------------------------------------------------------------------- |
| 6 | + |
| 7 | +namespace Dropbox.Api |
| 8 | +{ |
| 9 | + using System; |
| 10 | + using System.Text; |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// The client which contains endpoints which perform app-auth actions. |
| 14 | + /// </summary> |
| 15 | + public sealed partial class DropboxAppClient : DropboxClientBase |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class. |
| 19 | + /// </summary> |
| 20 | + /// <param name="appKey">The Dropbox app key (e.g. consumer key in OAuth).</param> |
| 21 | + /// <param name="appSecret">The Dropbox app secret (e.g. consumer secret in OAuth).</param> |
| 22 | + public DropboxAppClient(string appKey, string appSecret) |
| 23 | + : this(appKey, appSecret, new DropboxClientConfig()) |
| 24 | + { |
| 25 | + } |
| 26 | + |
| 27 | + |
| 28 | + /// <summary> |
| 29 | + /// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class. |
| 30 | + /// </summary> |
| 31 | + /// <param name="appKey">The Dropbox app key (e.g. consumer key in OAuth).</param> |
| 32 | + /// <param name="appSecret">The Dropbox app secret (e.g. consumer secret in OAuth).</param> |
| 33 | + /// <param name="config">The <see cref="DropboxClientConfig"/>.</param> |
| 34 | + public DropboxAppClient(string appKey, string appSecret, DropboxClientConfig config) |
| 35 | + : this(new DropboxRequestHandlerOptions(config, GetBasicAuthHeader(appKey, appSecret))) |
| 36 | + { |
| 37 | + } |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Initializes a new instance of the <see cref="T:Dropbox.Api.DropboxAppClient"/> class. |
| 41 | + /// </summary> |
| 42 | + /// <param name="options">The request handler options.</param> |
| 43 | + private DropboxAppClient(DropboxRequestHandlerOptions options) |
| 44 | + : base(new DropboxRequestHandler(options)) |
| 45 | + { |
| 46 | + } |
| 47 | + |
| 48 | + /// <summary> |
| 49 | + /// Gets the basic auth header from app key and app secret. |
| 50 | + /// </summary> |
| 51 | + /// <param name="appKey">The app key.</param> |
| 52 | + /// <param name="appSecret">The app secret.</param> |
| 53 | + /// <returns>The basic auth header.</returns> |
| 54 | + private static string GetBasicAuthHeader(string appKey, string appSecret) |
| 55 | + { |
| 56 | + if (appKey == null) |
| 57 | + { |
| 58 | + throw new ArgumentNullException("appKey"); |
| 59 | + } |
| 60 | + |
| 61 | + if (appSecret == null) |
| 62 | + { |
| 63 | + throw new ArgumentNullException("appSecret"); |
| 64 | + } |
| 65 | + |
| 66 | + var rawValue = string.Format("{0}:{1}", appKey, appSecret); |
| 67 | + return Convert.ToBase64String(Encoding.UTF8.GetBytes(rawValue)); |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments