Ejemplo n.º 1
0
		/// <summary>
		/// Verify incoming request for access token
		/// </summary>
		public static bool VerifyOAuthRequestTokenParameters(OAuthTokenRequest tokenRequest)
		{
			if (!string.IsNullOrEmpty(tokenRequest.grant_type) &&
				!tokenRequest.grant_type.Equals(OAuthConstants.ACCESS_TOKEN))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "Missing required parameter:  grant_type");
			}

			if (!string.IsNullOrEmpty(tokenRequest.scope) && !tokenRequest.scope.Equals(DEFAULT_SCOPE))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "The specified scope is invalid");
			}

			if (string.IsNullOrEmpty(tokenRequest.scope))
			{
				tokenRequest.scope = DEFAULT_SCOPE;
			}

			if (string.IsNullOrEmpty(tokenRequest.username))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "Missing required parameter:  username");
			}

			if (string.IsNullOrEmpty(tokenRequest.password))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "Missing required parameter:  password");
			}

			return true;
		}
Ejemplo n.º 2
0
		/// <summary>
		/// A method that executes request token flow
		/// </summary>
		public OAuthTokenResponse ExecuteTokenFlow(OAuthTokenRequest tokenRequest)
		{
			VerifyOAuthRequestTokenParameters(tokenRequest);

			long retrievedMemberId = VerifyCredentials(tokenRequest.username, tokenRequest.password);

			Guid accessTokenGuid = Guid.NewGuid();
			Guid refreshTokenGuid = Guid.NewGuid();

			DateTime validFrom = DateTime.UtcNow;
			DateTime validTo = validFrom.AddDays(1);

			AddMemberAuthorization(accessTokenGuid, retrievedMemberId, tokenRequest.scope, validFrom, validTo);

			return new OAuthTokenResponse
			{
				access_token = accessTokenGuid.ToString(),
				expires_in = null,
				refresh_token = refreshTokenGuid.ToString(),
				scope = tokenRequest.scope,
				token_type = TOKEN_TYPE_BEARER,
				MemberID = retrievedMemberId
			};
		}
Ejemplo n.º 3
0
		/// <summary>
		/// A method that executes refresh token flow
		/// </summary>
		public OAuthRefreshTokenResponse ExecuteRefreshTokenFlow(OAuthTokenRequest tokenRequest)
		{
			if (!string.IsNullOrEmpty(tokenRequest.scope) && !tokenRequest.scope.Equals(DEFAULT_SCOPE))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "The specified scope is invalid");
			}

			if (string.IsNullOrEmpty(tokenRequest.refresh_token))
			{
				throw new ApiException(HttpStatusCode.BadRequest, "Missing required parameter:  refresh_token");
			}

			Guid accessToken = Guid.NewGuid();
			long memberId = RefreshMemberAuthorization(tokenRequest.refresh_token, accessToken.ToString());
			var oAuthTokenResponse = new OAuthRefreshTokenResponse
			{
				MemberID = memberId,
				access_token = accessToken.ToString(),
				token_type = TOKEN_TYPE_BEARER,
				scope = tokenRequest.scope
			};

			return oAuthTokenResponse;
		}