コード例 #1
0
        /// <summary>
        /// Gets an instance of <code>MicrosoftTokenResponseBody</code> from the specified <code>JsonObject</code>.
        /// </summary>
        /// <param name="obj">The instance of <code>JsonObject</code> to parse.</param>
        public static MicrosoftTokenResponseBody Parse(JsonObject 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 = TimeSpan.FromSeconds(obj.GetInt32("expires_in")),
                Scope = scopes,
                AccessToken = obj.GetString("access_token"),
                AuthenticationToken = obj.GetString("authentication_token"),
                RefreshToken = obj.GetString("refresh_token")
            };
        
        }
コード例 #2
0
 /// <summary>
 /// Generates the authorization URL using the specified state and scope.
 /// </summary>
 /// <param name="state">The state to send to Microsoft's 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());
 }