/// <summary> /// ctor /// </summary> /// <param name="authEndPoint"></param> /// <param name="scope"></param> /// <param name="clientId"></param> /// <param name="clientSecret"></param> public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId, string clientSecret) { if (authEndPoint == null) throw new ArgumentNullException("authEndPoint"); if (string.IsNullOrEmpty(scope)) throw new InvalidOperationException("scope cannot be empty"); if (string.IsNullOrEmpty(clientId)) throw new InvalidOperationException("clientId cannot be empty"); _endPoint = authEndPoint; _scope = scope; _clientId = clientId; _clientSecret = clientSecret == "" ? null : clientSecret; // we want to change empty string to null so it gets culled form the parameter list }
/// <summary> /// ctor /// </summary> /// <param name="authEndPoint"></param> /// <param name="scope"></param> /// <param name="clientId"></param> /// <param name="clientSecret">Allowed to be null or empty</param> /// <exception cref="InvalidOperationException">scope or clientId are null or empty</exception> /// <exception cref="ArgumentNullException">authEndPoint is null</exception> public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId, string clientSecret) { if (string.IsNullOrEmpty(scope)) { throw new InvalidOperationException("scope cannot be empty"); } if (string.IsNullOrEmpty(clientId)) { throw new InvalidOperationException("clientId cannot be empty"); } _endPoint = authEndPoint ?? throw new ArgumentNullException("authEndPoint"); _scope = scope; _clientId = clientId; _clientSecret = clientSecret == "" ? null : clientSecret; // we want to change empty string to null so it gets culled form the parameter list }
private static async Task Go(EndPointInfo endpoint) { var keys = GetAppCredentials(endpoint.Name); IDeviceOAuth2 auth = new DeviceOAuth(endpoint, (string)keys.scopes, (string)keys.client_id, (string)keys.client_secret); auth.WaitingForConfirmation += (o, e) => { Console.CursorLeft = 0; Console.Write(e + " seconds left "); }; auth.PromptUser += (o, e) => { Console.WriteLine(""); Console.WriteLine("Go to this url on any computer:"); Console.WriteLine(e.VerificationUri); Console.WriteLine("And enter this code:"); Console.WriteLine(e.UserCode); Console.WriteLine(""); }; Console.WriteLine("Authenticating..."); try { var token = await auth.Authorize(null); dynamic profile = await auth.GetProfile(token); Console.WriteLine(""); Console.WriteLine("Name = " + profile.name); } catch (AggregateException e) { Console.WriteLine("Error:"); foreach (var inner in e.InnerExceptions) { Console.WriteLine(inner.Message); } } catch (Exception e) { Console.WriteLine("Error:"); Console.WriteLine(e.Message); } }
/// <summary> /// ctor /// </summary> /// <param name="authEndPoint"></param> /// <param name="scope"></param> /// <param name="clientId"></param> public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId) : this(authEndPoint, scope, clientId, null) { }
/// <summary> /// ctor /// </summary> /// <param name="authEndPoint"></param> /// <param name="scope"></param> /// <param name="clientId"></param> /// <exception cref="InvalidOperationException">scope or clientId are null or empty</exception> /// <exception cref="ArgumentNullException">authEndPoint is null</exception> public DeviceOAuth(EndPointInfo authEndPoint, string scope, string clientId) : this(authEndPoint, scope, clientId, null) { }