Example #1
0
func TestSpaceDelimitedStringNotGreater(t *testing.T) {
	assert.True(t, util.SpaceDelimitedStringNotGreater("", "bar foo qux"))

	assert.True(t, util.SpaceDelimitedStringNotGreater("foo", "bar foo qux"))

	assert.True(t, util.SpaceDelimitedStringNotGreater("bar foo qux", "foo bar qux"))

	assert.False(t, util.SpaceDelimitedStringNotGreater("foo bar qux bogus", "bar foo qux"))
}
Example #2
0
// getRefreshTokenScope returns scope for a new refresh token
func (s *Service) getRefreshTokenScope(refreshToken *RefreshToken, requestedScope string) (string, error) {
	var (
		scope = refreshToken.Scope // default to the scope originally granted by the resource owner
		err   error
	)

	// If the scope is specified in the request, get the scope string
	if requestedScope != "" {
		scope, err = s.GetScope(requestedScope)
		if err != nil {
			return "", err
		}
	}

	// Requested scope CANNOT include any scope not originally granted
	if !util.SpaceDelimitedStringNotGreater(scope, refreshToken.Scope) {
		return "", ErrRequestedScopeCannotBeGreater
	}

	return scope, nil
}