示例#1
0
        /// <summary>
        /// Parses the specified <code>obj</code> into an instance of <see cref="MicrosoftTokenResponseBody"/>.
        /// </summary>
        /// <param name="obj">The instance of <see cref="JObject"/> to be parsed.</param>
        /// <returns>Returns an instance of <see cref="MicrosoftTokenResponseBody"/>.</returns>
        public static MicrosoftTokenResponseBody Parse(JObject obj)
        {
            if (obj == null)
            {
                return(null);
            }

            // Convert the "scope" string to a collection of scopes
            MicrosoftScopeCollection scopes = new MicrosoftScopeCollection();

            foreach (string name in obj.GetString("scope").Split(' '))
            {
                MicrosoftScope scope = MicrosoftScope.GetScope(name) ?? MicrosoftScope.RegisterScope(name);
                scopes.Add(scope);
            }

            // Parse the rest of the response
            return(new MicrosoftTokenResponseBody(obj)
            {
                TokenType = obj.GetString("token_type"),
                ExpiresIn = obj.GetDouble("expires_in", TimeSpan.FromSeconds),
                Scope = scopes,
                AccessToken = obj.GetString("access_token"),
                AuthenticationToken = obj.GetString("authentication_token"),
                RefreshToken = obj.GetString("refresh_token")
            });
        }
 /// <summary>
 /// Generates the authorization URL using the specified state and scope.
 /// </summary>
 /// <param name="state">The state to send to the Microsoft OAuth login page.</param>
 /// <param name="scope">The scope of the application.</param>
 /// <returns>Returns an authorization URL based on <code>state</code> and <code>scope</code>.</returns>
 public string GetAuthorizationUrl(string state, MicrosoftScopeCollection scope)
 {
     return(GetAuthorizationUrl(state, scope.ToString()));
 }