/// <summary> /// Gets an instance of <code>SlackTokenInfo</code> from the specified <code>JsonObject</code>. /// </summary> /// <param name="obj">The instance of <code>JsonObject</code> to parse.</param> public static SlackTokenInfo Parse(JsonObject obj) { if (obj == null) return null; // Convert the "scope" string to a collection of scopes SlackScopeCollection scopes = new SlackScopeCollection(); foreach (string name in obj.GetString("scope").Split(',')) { SlackScope scope = SlackScope.GetScope(name) ?? SlackScope.RegisterScope(name); scopes.Add(scope); } // Parse the rest of the response return new SlackTokenInfo(obj) { AccessToken = obj.GetString("access_token"), Scope = scopes, TeamName = obj.GetString("team_name") }; }
/// <summary> /// Gets an authorization URL using the specified <code>state</code>. This URL will only make your application /// request a basic scope. /// </summary> /// <param name="state">A unique state for the request.</param> /// <param name="scope">The scope of the application.</param> public string GetAuthorizationUrl(string state, SlackScopeCollection scope) { if (String.IsNullOrWhiteSpace(state)) throw new ArgumentNullException("state"); if (scope == null) throw new ArgumentNullException("scope"); return String.Format( "https://slack.com/oauth/authorize?client_id={0}&redirect_uri={1}&state={2}&scope={3}", SocialUtils.UrlEncode(ClientId), SocialUtils.UrlEncode(RedirectUri), SocialUtils.UrlEncode(state), SocialUtils.UrlEncode(scope.ToString()) ); }